#include<iostream>
using namespace std;
class A
{
public:
A(int a){ x = a; }
void printfA(){ cout << "x=" << x << endl; }
private:
int x;
};
class B :public A
{
public:
B(int b, int c) :A(b){ y = c; }//这个地方不理解,定义了一个B带两个参数的构造函数之后:A(b){ y = c; }是什么意思?
void printfB(){ printfA(); cout << "y=" << y << endl; }
private:
int y;
};
int main()
{
B temp(1, 2);
temp.printfB();
return 0;
}
using namespace std;
class A
{
public:
A(int a){ x = a; }
void printfA(){ cout << "x=" << x << endl; }
private:
int x;
};
class B :public A
{
public:
B(int b, int c) :A(b){ y = c; }//这个地方不理解,定义了一个B带两个参数的构造函数之后:A(b){ y = c; }是什么意思?
void printfB(){ printfA(); cout << "y=" << y << endl; }
private:
int y;
};
int main()
{
B temp(1, 2);
temp.printfB();
return 0;
}