相关疑难解决方法(0)

我可以在C++中从另一个构造函数(构造函数链接)调用构造函数吗?

作为C#开发人员,我习惯于运行构造函数:

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

    public Test(int count) : this() {
        DoSomethingWithCount(count);
    }

    public Test(int count, string name) : this(count) {
        DoSomethingWithName(name);
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在C++中执行此操作?

我尝试调用类名并使用'this'关键字,但都失败了.

c++ constructor

879
推荐指数
10
解决办法
44万
查看次数

标签 统计

c++ ×1

constructor ×1