codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#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); }
Private
[
?
]
Run code
Submit