> cat nevercall.cpp
class Transaction {
public:
Transaction();
virtual void logTransaction() const = 0;
// ...
};
Transaction::Transaction()
{
//...
logTransaction();
}
class BuyTransaction: public Transaction {
public:
virtual void logTransaction() const;
//...
};
class SellTransaction: public Transaction {
public:
virtual void logTransaction() const;
// ...
};
int main()
{
BuyTransaction b;
}
Meyerのサンプルコードにあるように、usingは、純粋-Weffc++
である場合(およびその場合のみ)にこれについて警告します。virtual void Transaction::logTransaction() const
> g++ -Weffc++ nevercall.cpp -o nevercall
nevercall.cpp:1:7: warning: 'class Transaction' has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
nevercall.cpp: In constructor 'Transaction::Transaction()':
nevercall.cpp:12:20: warning: pure virtual 'virtual void Transaction::logTransaction() const' called from constructor [enabled by default]
nevercall.cpp: At global scope:
nevercall.cpp:15:7: warning: 'class BuyTransaction' has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
nevercall.cpp:22:7: warning: 'class SellTransaction' has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]