code_junkie

C++ Anyway to prevent a method from being over ridden in sub classes?

Nov 10th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. class Base {
  2. public:
  3. bool someGuaranteedResult() { return true; }
  4. };
  5.  
  6. class Child : public Base {
  7. public:
  8. bool someGuaranteedResult() { return false; /* Haha I broke things! */ }
  9. };
  10.  
  11. Parent* obj = new Child();
  12.  
  13. int foo() { return 1; }
  14.  
  15. int foo() { return 2; }
Add Comment
Please, Sign In to add comment