combined.cpp

来自「Thinking in C++ 2nd edition source code 」· C++ 代码 · 共 38 行

CPP
38
字号
//: C14:Combined.cpp
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Inheritance & composition

class A {
  int i;
public:
  A(int I) { i = I; }
  ~A() {}
  void f() const {}
};

class B {
  int i;
public:
  B(int I) { i = I; }
  ~B() {}
  void f() const {}
};

class C : public B {
  A a;
public:
  C(int I) : B(I), a(I) {}
  ~C() {} // Calls ~A() and ~B()
  void f() const {  // Redefinition
    a.f();
    B::f();
  }
};

int main() {
  C c(47);
} ///:~

⌨️ 快捷键说明

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