code_junkie

When should you not use virtual destructors?

Nov 12th, 2011
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. A *x = new B;
  2. delete x; // ~B() called, even though x has type A*
  3.  
  4. class MutexLock {
  5. mutex *mtx_;
  6. public:
  7. explicit MutexLock(mutex *mtx) : mtx_(mtx) { mtx_->lock(); }
  8. ~MutexLock() { mtx_->unlock(); }
  9. private:
  10. MutexLock(const MutexLock &rhs);
  11. MutexLock &operator=(const MutexLock &rhs);
  12. };
Add Comment
Please, Sign In to add comment