This documentation is archived and is not being maintained.

6 __gc Interfaces

Visual Studio .NET 2003

A __gc interface embodies the COM notion of an interface. An interface declaration is similar to a class declaration, except for the class-key __interface. The __gc keyword is used when declaring a __gc interface since __gc interface pointers must point to __gc classes.


// __gc_interfaces.cpp
// compile with: /clr /LD
#using <mscorlib.dll>
__gc __interface Ibase { void f(); };

Any number of __gc interfaces can be implemented by a __gc class. Member functions in the __gc class implement those with the same name and signature in the __gc interface.


The following features are supported for __gc interfaces:

  • All methods of an interface are implicitly pure virtual. Neither the keyword virtual nor the suffix =0 is required on an interface method declaration, although both are allowed.
  • A __gc interface can contain a nested declaration of a __value enum (Section 12).
  • The __abstract keyword (Section 17) is redundant for an interface, but is allowed.
  • All __gc interfaces implicitly derive from System::Object. Explicit derivation from System::Object is redundant, but is allowed.


The following constraints apply to __gc interfaces:

  • They shall contain no data members.
  • They shall contain no static members of any kind.
  • They shall contain no declarations of classes, managed or unmanaged.
  • They shall contain no access specifier other than public, which is the default.
  • They shall not provide an implementation for any of their methods.
  • They shall explicitly inherit only from other interfaces or the class System::Object.
  • They shall not be marked with the __sealed keyword (Section 18).
  • They shall not be nested inside a __gc class or __value class.