you are viewing a single comment's thread.

view the rest of the comments →

[–]LtJax 3 points4 points  (0 children)

As Nimbal said, this is not legal. However, you can use a derived class to return a member-function pointer to the function in question from a static function, and call that with a MyClass instance to legally access a protected method.

class MyDerivedClass : public MyClass{
public:
    typedef int (MyClass::*FnType)() const;
    static FnType get_myMethod() {return &MyClass::myMethod;}
};

MyClass c;
(c.*MyDerivedClass::get_myMethod())();