标签:
在构造以及析构函数期间不要调用virtual函数,因为这类调用从不下降到derived class中。例如说下面这个例子:
1 class Transaction{ 2 public: 3 Transaction(); 4 virtual void logTransactions()s const = 0; 5 //... 6 }; 7 Transaction::Transaction() 8 { 9 //... 10 logTransaction(); 11 } 12 class BuyTransaction : public Transaction{ 13 public: 14 virtual void logTransaction() const; 15 ... 16 }; 17 class SellTransaction : public Transaction{ 18 public: 19 virtual void logTransaction() const; 20 ... 21 };
标签:
原文地址:http://www.cnblogs.com/-wang-cheng/p/4855572.html