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

📄 visitor.h

📁 Think in C++ 第二版源码
💻 H
字号:
//: C25:Visitor.h

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

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

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// The base interface for visitors

// and template for visitable Trash types

#ifndef VISITOR_H

#define VISITOR_H

#include "Trash.h"

#include "Aluminum.h"

#include "Paper.h"

#include "Glass.h"

#include "Cardboard.h"



class Visitor {

public:

  virtual void visit(Aluminum* a) = 0;

  virtual void visit(Paper* p) = 0;

  virtual void visit(Glass* g) = 0;

  virtual void visit(Cardboard* c) = 0;

};



// Template to generate visitable 

// trash types by inheriting from originals:

template<class TrashType> 

class Visitable : public TrashType {

protected:

  Visitable () : TrashType(0) {}

  friend class TrashPrototypeInit;

public:

  Visitable(double wt) : TrashType(wt) {}

  // Remember "this" is pointer to current type:

  void accept(Visitor& v) { v.visit(this); }

  // Override clone() to create this new type:

  Trash* clone(const Trash::Info& info) {

    return new Visitable(info.data());

  }

};

#endif // VISITOR_H ///:~

⌨️ 快捷键说明

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