相关疑难解决方法(0)

在初始化变量之前调用父类构造函数吗?

在初始化变量之前调用父类构造函数,还是编译器首先初始化类的变量?

例如:

class parent {
  int a;
public:
  parent() : a(123) {};
};

class child : public parent {
  int b;
public:
            // question: is parent constructor done before init b?
  child() : b(456), parent() {};
}
Run Code Online (Sandbox Code Playgroud)

c++ inheritance class

12
推荐指数
1
解决办法
5724
查看次数

标签 统计

c++ ×1

class ×1

inheritance ×1