b&d2.h

来自「适合初学者学习以及程序员回顾」· C头文件 代码 · 共 42 行

H
42
字号
// B&D2.h
#include <iostream>
using namespace std;

//---- 宣告类别 Base --------

class Base
{
 private:
   int i;
 public:
   Base():  i(3)
     {cout << "呼叫 Base 预设建构函数" << endl; }
   Base(int N): i(N)
     {cout << "呼叫 Base 建构函数" << endl; }
   ~Base()
     {cout << "呼叫 Base 解构函数" << endl;}
   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 预设建构函数" << endl; }
   Derived(int M, int N) : Base(M), i(N)
     {cout << "呼叫 Derived 建构函数" << endl; }
   ~Derived()
     {cout << "呼叫 Derived 解构函数" << endl;}
   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();}
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?