但是这种定义,在link的时候出现 vtable ..undefined reference to 的错误,原因是gcc实现
C++规范的时候的问题,解决这个问题,是需要必须顶一个空的virtual,这样造成了,编译器
检查强迫子类覆盖的失效,非常的不爽。virtual myfunction (){}; 语法来规避错误
有人建议使用 virtual myfunction ()=0;但没有成功
http://gcc.gnu.org/faq.html#vtables
class Port { private: char *brand; char style[20]; // i.e. tawny, ruby, vintage int bottles; public: Port(const char *br = "none", const char *st = "none", int b = 0); Port(const Port &p); // copy constructor virtual ~Port() { delete [] brand;} Port & operator=(const Port &p); Port & operator+=(int b); Port & operator-=(int b); int BottleCount() const {return bottles;} virtual void Show() const; friend ostream &operator<<(ostream &os, const Port &p); }; class VintagePort : public Port { private: char * nickname; // i.e. The Noble, or Old Velvet, etc. int year; // vintage year public: VintagePort(); VintagePort(const char *br, int b, const char *nn, int y); VintagePort(const VintagePort &vp); ~VintagePort() {delete [] nickname;} void Show() const; friend ostream & operator<<(ostream &os, const VintagePort & vp); };