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

📄 early.cpp

📁 希望我提供的代码对大家有帮助
💻 CPP
字号:
//: C15:Early.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// Early binding & virtuals

#include <iostream>

using namespace std;



class Base {

public:

  virtual int f() const { return 1; }

};



class Derived : public Base {

public:

  int f() const { return 2; }

};



int main() {

  Derived d;

  Base* b1 = &d;

  Base& b2 = d;

  Base b3;

  // Late binding for both:

  cout << "b1->f() = " << b1->f() << endl;

  cout << "b2.f() = " << b2.f() << endl;

  // Early binding (probably):

  cout << "b3.f() = " << b3.f() << endl;

} ///:~

⌨️ 快捷键说明

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