C++继承的例子 (1)

#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;
}
    

原文地址:https://www.cnblogs.com/robbychan/p/3786915.html