MSVC direct constructor call extension

被刻印的时光 ゝ 提交于 2019-12-03 14:07:58

It is not constructor delegating. Try following code:

#include <iostream>

class C{
public:
    C() { std::cout << "C" << std::endl; }
    ~C() { std::cout << "~C" << std::endl; }
};

struct foo
{
    int m;
    C c;
    foo(int p) : m(p) { std::cout << "foo("<<p<<")\n"; }
    foo()
        : m(0)
    {
        this->foo::foo(42);
        std::cout << "foo(), " << m << "\n";
    }
};

int main()
{
    foo f;
}

According to output field "c" is initialized twice but destroyed only once. As zneak noted, It is similar to new (this) foo(42).

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