#include <iostream>
#include <cstdio>
using std::cin;
using std::cout;
using std::endl;
class A {
private :
int a;
public :
A() : a(100) {
cout << "无参构造A" << endl;
}
A(int k) : a(k) {}
};
class B : public A {
private :
int b;
public :
B() : b(900) {}
void print() {
//cout << "a : " << a << endl; 因为是 父类A 的私有成员
cout << "b : " << b << endl;
}
};
int main() {
B* pb = new B();
pb->print();
return 0;
}
C++继承的例子 (1)
最新推荐文章于 2023-04-10 22:51:59 发布