class test{
protected:
int a;
public:
test(int a = 0);
~test();
void show();
};
class B :public test {
private:
int b;
public:
B(int b = 0);
void show();
};
#include <iostream>
#include "test.h"
using namespace std;
test::test(int a) {
cout << "a = " << a << endl;
cout << "this a = " << this->a << endl;
this->a = a;
cout << "基类实例化:a : " << this->a << endl;
}
test::~test() {
cout << "退出基类实例化" << endl;
}
void test::show() {
cout << "a : " << a << endl;
}
B::B(int b) : test(a)
{
cout << "派生类实例化" << endl;
cout << "b = " << b << endl;
cout << "this b = " << this->b << endl;
this->b = a;
}
void B::show() {
cout << "b : " << b << endl;
}
#include <iostream>
#include "test.h"
using namespace std;
int main() {
B t1;
t1.show();
return 0;
}
请问为什么第一行的输出a不是0?
怎么改才能让第一行的输出a是0?