From http://www.parashift.com/c++-faq-lite/basics-of-inheritance.html#faq-19.5
A member (either data member or member function) declared in a protecte
Well, if friend is ok, then this angle may as well be ok:
#include
class X {
private:
int var;
protected:
virtual void fun() {
var = 10;
std::cout << "\nFrom X" << var;
}
static void Fun(X& x) {
x.fun();
}
};
class Y : public X {
private:
int var;
public:
virtual void fun() {
var = 20;
std::cout << "\nFrom Y" << var;
}
void call() {
fun();
X objX;
objX.fun(); /* << ne-ne */
Fun(objX); /* << ok */
}
};
Of course, be mindful of the type you pass to X::Fun if you use this as-is.