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

前端 未结 4 806
醉酒成梦
醉酒成梦 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:45

    When you said "I know that there is no way to do this in pure C++" you were in error. It is possible to do that in native C++. You can use the placement new operator to do so.

    class A 
    { 
    
    public:
    
       A(int p) : p(p) 
       { new(this)A(); }
    
       A() : p(1) {}      
    
       int p; 
    };
    

提交回复
热议问题