[ create a new paste ] login | about

Link: http://codepad.org/LUGSNPdh    [ raw code | output | fork ]

epper - C++, pasted on Jan 3:
#include <iostream>
using namespace std;

class A {
public:   // NOTE: Here bar() is public
  virtual string bar(){return "A::bar";}
};

class B : public A {
private:   // NOTE: Here bar() is private
  virtual string bar(){return "B::bar";}
};

void foo(A* a) {
  cout << a->bar() << endl;
}

int main () {
  B* b = new B();
  
  // We pass a B object to the foo function for which the bar method is
  // private and so should not be possible to call it from outside the class...
  // Anyway the bar() method will be called successfully returning "B::bar"
  foo(b);
}


Output:
1
B::bar


Create a new paste based on this one


Comments: