privmult.cpp

来自「C/C++使用技巧1001例一书的配套代码」· C++ 代码 · 共 40 行

CPP
40
字号
#include <iostream.h>

class One {
 public:
  One(void) { cout << "Constructor for One\n"; 
              one = 1; };
  int one;
};

class Two {
 public:
  Two(void) { cout << "Constructor for Two\n"; 
              two = 2; };
  int two;
};

class Three {
 public:
  Three(void) { cout << "Constructor for Three\n"; 
                three = 3; };
  int three;
};


class Derived: private One, private Three, public Two {
 public:
   Derived(void) : One(), Two(), Three() {
     cout << "Derived constructor called\n"; };

   void show_value(void) { cout << one << two << three << endl; };
};

void main(void)
 {
   Derived my_class;
   my_class.show_value();
   cout << my_class.two;
 }

⌨️ 快捷键说明

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