views:

49

answers:

2

I am updating some old c++ code and am finding that many of the classes are defined as:

public __gc class NameOfClass{  }

I found a little bit of information about __gc here, but it seems to only come up with information for VS 2003. The MSDN documentation that came with my copy of VS 2005 indicates that __gc may not be in use anymore.

I'm a C# guy myself, so I want to make sure I don't make a mistake when updating this code. Is garbage collecting automatic for c++ classes in .NET 2.0 and greater? Or has the __gc keyword been replaced in some way?

+1  A: 

It has been somewhat (possibly entirely) replaced; I believe it's still supported for BC, but there was a new mechanism introduced with VS2005 which made managed types more explicit. See: http://msdn.microsoft.com/en-us/library/xey702bw%28v=VS.80%29.aspx

For reference, the big problem with the old syntax was that it added overloaded usage of standard C++ syntax, which was dependent on the underlying types, which was horribly confusing in code. The new syntax is much better for differentiating managed handles from unmanaged pointers.

Nick
+1  A: 

You are looking at C++ with managed extensions which was a brief and failed attempt to add clr functionality to cpp using some rather inventive syntax. I believe from 2005 onward c++ cli was fully supported which is a full implementation of the clr in C++. Take a look at this for migrating advice from m.

rerun
Thanks for the help. The link gave me exactly what I needed: "In the original language definition, a reference class type is prefaced with the __gc keyword. In the revised language, the __gc keyword is replaced by one of two spaced keywords: refclass or refstruct. "
Slider345