GeeksforGeeks » C/C++ Programming Questions
C++: possible encapsulation failure
(2 posts)-
Consider this program.
#include <iostream> using namespace std; class Base { public: virtual void foo() { cout << "Base foo()\n"; } }; class Derived : public Base { private: void foo() { cout << "Derived foo() \n"; } }; int main() { Base *bp; Derived d; bp = &d; bp->foo(); }Output: Derived foo()
So it is possible to access a private data member this way. -
nice finding :)
Reply
You must log in to post.