0

I wanted to write shell extensions for windows in plain C++, but then I got confused by the keyword interface. In many articles I read that I can create interfaces in C++ by writing classes containing only virtual methods without any code. For example:

class IIsThisAnInterface_QuestionMark {
    virtual MyMethod (
        int firstParameter,
        double secondParameter) = 0;
    virtual AnotherMethod (
        wchar_t *firstParameter) = 0;
}

But the author of this article defined interfaces by using the interface keyword. So my question is: How to correctly define interfaces in C++? (Becuase I grew up in C#'s world, I know interfaces as constructs specifying methods for classes that are implementing these interfaces.)

Cubi73
  • 1,669
  • 3
  • 24
  • 43
  • 5
    There's no `interface` keyword in C++. The header included in that example probably defined it as a macro. – T.C. Jul 14 '14 at 16:48
  • this was the first site in google when i searched for "c++ interface" http://stackoverflow.com/questions/318064/how-do-you-declare-an-interface-in-c – iedoc Jul 14 '14 at 16:49
  • That `interface` keyword is part of Component Object Model (COM). You may wish to add the COM tag and update the question. – SE_net4 the downvoter Jul 14 '14 at 16:53
  • AFAIK the `interface`-stuff is specific to the `COM`-Interface stuff. Do not know whether you need this for shell extensions. – Tobias Jul 14 '14 at 16:55
  • 1
    http://msdn.microsoft.com/en-us/library/50h7kwtb.aspx there is a microsoft extension that adds a keyword `__interface`. – Alexander Oh Jul 14 '14 at 16:55
  • 1
    1st: I didn't know that there is no `interface` keyword in C++. And you are right, in the `ObjBase.h` header is following macro defined: `#define interface struct`. 2nd: I believe you can mark this question as duplicate, because I was asking how to correctly define an interface. (I already marked it as a duplicate) – Cubi73 Jul 14 '14 at 17:00
  • @Tobias Shell extensions are little programs extending the ability of windows. They have to be written as a COM component. – Cubi73 Jul 14 '14 at 17:11

1 Answers1

2

C++ doesn't strictly provide interfaces in the way that some languages do. The C++ mechanism is to provide a class with one or more pure virtual methods that declare the desired interface. Strictly speaking such a class is just an abstract class, but one could consider calling it an interface that child classes would then implement.

Mark B
  • 91,641
  • 10
  • 102
  • 179