如何将重载的构造函数调用转发到C ++ / CLI中的另一个构造函数 [英] How to forward overloaded constructor call to another constructor in C++/CLI
问题描述
我知道没有办法在纯C ++ 中执行此操作,但是我想知道是否可以从另一个构造函数的初始化列表中调用构造函数在C ++ / CLI,就像在C#中可以做的一样。
I know that there is no way to do this in pure C++, but I was wondering if it is possible to call a constructor from another constructor's initialization list in C++/CLI, same way one can do it in C#.
示例:
ref class Foo {
Foo() {}
Foo(int i) : Foo() {}
}
推荐答案
。它尚未在语言中提供。但是有一个正式的提案,你会在语言规范。鉴于Microsoft对C ++ / CLI的立场,这不太可能很快看到一天的光。
It is called a "delegating constructor". It is not available in the language yet. But there's a formal proposal, you'll find it in annex F.3.1 of the language specification. Given Microsoft's stance towards C++/CLI, that is unlikely to see the light of day anytime soon.
UPDATE:委托构造函数确实有超过附件中的建议的生活,它们被添加到标准的C ++ 11语言规范中。 Microsoft一直在努力实现C ++ 11添加。委托构造函数最终为VS2013。他们也在该版本的C ++ / CLI中工作。
UPDATE: delegating constructors did have a life beyond the proposal in that annex, they were added to the standard C++11 language specification. Microsoft has been working on getting the C++11 additions implemented. Delegating constructors finally made it for VS2013. And they also work in C++/CLI in that edition.
这篇关于如何将重载的构造函数调用转发到C ++ / CLI中的另一个构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!