How to forward overloaded constructor call to another constructor in C++/CLI

前端 未结 4 804
醉酒成梦
醉酒成梦 2020-12-20 17:50

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, s

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 18:42

    You can do following

    ref class A
    {
    public:
        A(int p) : p(p) { this->A::A(); }
        A() : p(1) {}
    
        int p;
    };
    

    It is not valid C++ code , but VC compiles it fine :)

提交回复
热议问题