⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compclass2.h

📁 适合初学者学习以及程序员回顾
💻 H
字号:
// CompClass2.h

#ifndef COMPCLASS2_H
#define COMPCLASS2_H
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::cerr;

//---- 宣告类别 Component --------
class Component
{
  private:
    int I;
  public:
    // 类别 Component 的建构函数
    Component (): I(1)
     {cout << "呼叫 Component 预设建构函数" << endl; }
    Component (int N): I(N)
     {cout << "呼叫 Component 建构函数" << endl;}
    // 类别 Component 的解构函数
    ~Component()
     {cout << "呼叫 Component 解构函数" << endl;}
    int Get() const   {return I;}
    void Double()     {I*=2;}
};

//---- 宣告类别 Host --------
class Host
{
  private:
    int k;
    Component C1, C2;
  public:
    Component C3;
    // 类别 Host 的建构函数
    Host() : k(1), C1(1), C2(1), C3(1)
    {cout << "呼叫 Host 预设建构函数" << endl; }
    Host(int L, int M, int N, int P)
           : k(L), C1(M), C2(N), C3(P)
    {cout << "呼叫 Host 建构函数" << endl; }
    // 类别 Host 的解构函数
    ~Host()
      {cout << "呼叫 Host 解构函数" << endl;}
    int  Get() const  {return k;}
    void Double()     {k*=2;}
    void DoubleComp()
      {C1.Double(); C2.Double(); C3.Double();}
    int  GetC1()      {return C1.Get();}
    int  GetC2()      {return C2.Get();}
};

#endif

⌨️ 快捷键说明

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