auto foo = ref new Foo();什么是“参考”?
我正在观看来自 //build/ 的视频,一些 MS 开发人员在他们的 C++11 程序中使用了这样的语法:
auto foo = ref new Foo();
我理解这一行中除了“ref”之外的所有内容的作用。这意味着什么?
I was watching a video from, //build/ and several of the MS developers were using a syntax like this in their C++11 programs:
auto foo = ref new Foo();
I understand what everything does in this line except "ref". What does that mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
即将推出的 Visual C++ 编译器添加了此语法来处理 WinRT 对象(这些对象又是下一代 COM,我们现在经历了什么?COM、DCOM、COM+、ActiveX,...)
该行几乎相当于:
但还有一个新版本的
com_ptr_t
,使用语法Foo^
。The forthcoming Visual C++ compiler adds this syntax for dealing with WinRT objects (which are in turn the next generation of COM, what have we gone through now? COM, DCOM, COM+, ActiveX, ...)
That line is nearly equivalent to:
But there's a new version of
com_ptr_t
as well, using the syntaxFoo^
.“ref new”是一个 2 令牌关键字。它指示编译器实例化一个 Windows 运行时对象并自动管理该对象的生命周期(通过“^”运算符)。
实例化 Windows 运行时对象会导致分配,但它不必位于堆上。
"ref new" is a 2 token keyword. It instructs the compiler to instantiate a windows runtime object and automatically manage the lifetime of the object (via the "^" operator).
Instantiating a windows runtime object causes an allocation, but it does not have to be on the heap.
在这种情况下,ref 代表引用计数。使用 ref 的类是 WinRT 组件,具有开箱即用的引用计数机制。
ref in this case stands for reference counting. Classes using ref are WinRT component which have reference count machanisms out of the box.