开发者

When to use __gc for classes and structs?

I am updating some old c++ code and am finding that many of the classes are define开发者_StackOverflowd 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜