Export (0) Print
Expand All

__gc

Visual Studio .NET 2003

Declares a __gc type.

__gc array-specifier
__gc class-specifier
__gc struct-specifier
__gc interface-specifier
__gc pointer-specifier
__gc new

Remarks

A __gc type is a C++ language extension that simplifies .NET Framework programming by providing features such as interoperability and garbage collection.

For information and examples on declaring __gc types, see:

Note   Every member function of an abstract __gc class must be defined unless the member function is pure virtual.

For more information on the rules for __gc types, see 4 __gc Classes.

For more information on creating and using __gc types, see Managed Extensions for C++ Programming.

In Managed Extensions for C++, the equivalents to a C# class and a C# struct are as follows:

Managed Extensions for C++ C# For more information
__gc struct
or
__gc class
class class keyword
__value struct
or
__value class
struct struct keyword

Example

In the following example, a managed class (X) is declared with a public data member, which is manipulated through a managed pointer:

// keyword__gc.cpp
// compile with: /clr
#using <mscorlib.dll>
using namespace System;

__gc class X
{
public:
   int i;
   int ReturnInt() { return 5; }
};

int main()
{
// Because X is a __gc class, this automatically makes px a __gc pointer
   X* px;
   px = new X;               // creates a managed object of type X
   Console::WriteLine(px->i);

   px->i = 4;                // modifies X::i through px
   Console::WriteLine(px->i);

   int n = px->ReturnInt();  // calls X::ReturnInt through px
   Console::WriteLine(n);
   return 0;
}

Output

0
4
5

See Also

Managed Extensions for C++ Reference | C++ Keywords | 4 __gc Classes

Show:
© 2015 Microsoft