Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

interface, __interface

http://msdn.microsoft.com/en-us/library/7st4ta52.aspx

C++ and Microsoft Specific

A Visual C++ interface can be defined as follows:

  • Can inherit from, at most, one base class.
  • Can only contain public, pure virtual methods.
  • Cannot contain static methods.
  • Cannot contain data members.

A C++ class or struct could be implemented with these rules, but interface (or __interface) enforces them.

By default, only the __interface keyword will be enabled. If you want to use interface as a keyword, see pragma keyword. If you use interface, be aware that some header files may still define:

#define interface struct

In this case, you would have to issue:

#undef interface

For example, the following is a sample interface definition:

interface IMyInterface {
HRESULT CommitX();
HRESULT get_X(BSTR* pbstrName);
};

Notice that you do not have to explicitly indicate that the function is pure virtual. An equivalent declaration for the first function would be:

virtual HRESULT CommitX() = 0;

END C++ and Microsoft Specific

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.