适合初学者学习以及程序员回顾
源代码在线查看: b&d2.h
// B&D2.h
#include
using namespace std;
//---- 宣告类别 Base --------
class Base
{
private:
int i;
public:
Base(): i(3)
{cout Base(int N): i(N)
{cout ~Base()
{cout void Set(int N) {i=N;}
int Get() const {return i;}
void Double() {i*=2;}
void Triple() {i*=3;}
};
//---- 宣告类别 Derived --------
class Derived : public Base
{
private:
int i;
public:
Derived(): i(5)
{cout Derived(int M, int N) : Base(M), i(N)
{cout ~Derived()
{cout void Set(int N) {i=N;}
void SetBase(int N) {Base::Set(N);}
void Double() {i*=2;}
int Get() const {return i;}
int GetBase() const {return Base::Get();}
};