Advertisement
Guest User

calling pure virtual

a guest
Mar 20th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. ##### [11:08:10] # [dare2be@PC10CIS:/tmp] #####
  2. $ cat b.cpp
  3. class B {
  4. public:
  5.   B() { f1(); }
  6.   // call from ctor to “impure” virtual; looks safe
  7.   virtual void f1() { f3(10); } // call to pure virtual from non-ctor; looks safe
  8.   virtual void f3(int x) = 0;
  9. };
  10.  
  11. class D : public B {
  12.   void f3(int x) {}
  13. };
  14.  
  15. int main() {
  16.   D d;
  17.   return 0;
  18. }
  19. ##### [11:08:24] # [dare2be@PC10CIS:/tmp] #####
  20. $ g++ -Wall b.cpp -o b
  21. ##### [11:08:35] # [dare2be@PC10CIS:/tmp] #####
  22. $ ./b
  23. pure virtual method called
  24. terminate called without an active exception
  25. Aborted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement