class A
{
public:
A():i(123) /相当于给i赋值
{
}
A(int a)
{
i = a;
}
private:
int i;
};
class B:public A
{
public:
B():A(1), b(456) 相当于调用A的有参构造函数,b相当于赋值为456
{
}
private:
int b;
};
C++类中:作用
最新推荐文章于 2024-07-18 11:49:02 发布
class A
{
public:
A():i(123) /相当于给i赋值
{
}
A(int a)
{
i = a;
}
private:
int i;
};
class B:public A
{
public:
B():A(1), b(456) 相当于调用A的有参构造函数,b相当于赋值为456
{
}
private:
int b;
};