我在我正在处理的代码库中看到一些代码如下:
ZfooName::ZfooName(int magoo)
: ZfooName()
{
fGoo = magoo;
}
我假设这是一个 C++11 功能,因为它在 VS2012 中中断,但这是什么意思?
最佳答案
这是 C++11 中的新特性。它称为委托(delegate)构造函数。
构造函数首先调用默认构造函数(被委托(delegate)给的构造函数)。默认构造函数返回后,执行委托(delegate)构造函数的主体。
参见 http://www.stroustrup.com/C++11FAQ.html#delegating-ctor和 https://en.cppreference.com/w/cpp/language/initializer_list#Delegating_constructor了解更多信息。
关于c++ - :className() mean in a constructor for className? 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51973151/