这是调用基类构造函数的合法方式吗?
基类如下
class base_class
{
public:
base_class(int x, int y);
protected:
int a;
int b;
};
base_class::base_class(int x,int y)
{
a=x;
b=y;
}
派生类如下
class derived_class: public base_class
{
public:
derived_class(int x,int y,int z);
protected:
int c;
};
derived_class:: derived_class(int x,int y,int z):base_class(x,y) /*Edited and included the scope resolution operator*/
{
c=z;
}
这种在 C++ 中定义派生类构造函数的方式是否合法,如果是,如何调用基类构造函数?