bird.hpp

来自「深入浅出设计模式(书配套c++源代码)。包含20个设计模式的c++实现。」· HPP 代码 · 共 49 行

HPP
49
字号
#ifndef	_HFDP_CPP_FLYWEIGHT_FOWLWEIGHT_BIRD_HPP_#define _HFDP_CPP_FLYWEIGHT_FOWLWEIGHT_BIRD_HPP_#include "FowlWeight.hpp"namespace HeadFirstDesignPatterns {namespace FlyWeight {namespace FowlWeight {// Unshared ConcreteFlyweightclass Bird : public Fowl {	private: const Fowl* _fowl;	private: int _number;	private: double _weight;	private: Bird( const Bird& ); // Disable copy constructor    private: void operator=( const Bird& ); // Disable assignment operator	public: Bird( const Fowl* fowl, int number = 0, double weight = 0.0 ) :		_fowl( fowl ), _number( number ), _weight( weight ) { assert( fowl );	}	public: void quack() const { assert( _fowl );		_fowl->quack();	}	public: void swim() const { assert( _fowl );		_fowl->swim();	}	public: double getWeight() const {		return _weight;	}	public: double getNumber() const {		return _number;	}	public: std::string toString() const { assert( _fowl );		std::stringstream value; 		value << "Bird #"<< _number + 1 << ", ";		value << "weighs " << _weight << " pounds, ";		value << "is a " << _fowl->toString();		return value.str();	}};} // namespace FowlWeight} // namespace FlyWeight} // namespace HeadFirstDesignPatterns#endif

⌨️ 快捷键说明

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