Can I call a constructor from another constructor (do constructor chaining) in C++?

前端 未结 15 2519
暖寄归人
暖寄归人 2020-11-22 01:27

As a C# developer I\'m used to running through constructors:

class Test {
    public Test() {
        DoSomething();         


        
15条回答
  •  Happy的楠姐
    2020-11-22 01:37

    It is worth pointing out that you can call the constructor of a parent class in your constructor e.g.:

    class A { /* ... */ };
    
    class B : public A
    {
        B() : A()
        {
            // ...
        }
    };
    

    But, no, you can't call another constructor of the same class.

提交回复
热议问题