What is the meaning of this strange syntax

与世无争的帅哥 提交于 2019-12-11 00:48:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!