Private method has been invokated as interface
In program below a private method has been invokated as interface.
It is techically clear, but it is intuitively unclear.
------ foobar.cpp ------
#include <iostream>
using namespace std;
class Base
{
public:
virtual void foo() = 0;
};
class Derived : public Base
{
private:
void foo() { cout << "foo(): I am private" << endl; }
};
int main ()
{
Base* p = new Derived();
// ----------------------------------------------------------
// Checks public Base::foo() in compile-time;
// invokes private Derived::foo() in run-time
p->foo();
// ----------------------------------------------------------
return 0;
}
------ foobar.cpp ------
------ Run ------
$ ./a.exe
foo(): I am private
-----------------
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]