问题
Today I saw the following syntax. Can anybody tell me the meaning of this:
System::ComponentModel::Container ^components;
I got this code in Visual C++, after I used a wizard to create a service.
回答1:
The ^
operator (not to be confused with the binary XOR operator) is specific to C++/CLI.
It is used to declare a handle to a .NET managed object.
A handle is a reference to the object which differs from traditional C++ pointers in the fact that it allows Garbage Collection to function correctly for the referenced object, making manual object deletion unnecessary.
This syntax supersedes the managed C++ extensions' __gc
pointers.
More details can be found here: http://en.wikipedia.org/wiki/C%2B%2B/CLI
回答2:
It is C++/CLI handle. C++/CLI is Microsoft's managed extension to C++ to provide compatibility with .NET CLR.
Read here a little bit more about C++/CLI.
回答3:
This is managed C++, which is not C++.
The line defines a variable components which is a managed pointer to System::ComponentModel::Container
来源:https://stackoverflow.com/questions/5015723/what-is-the-meaning-of-this-strange-syntax