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

posted @ 2013-11-12 11:49  小尼人00  阅读(152)  评论(0编辑  收藏  举报