problems taking a pointer to member-function of a protected method in a derived class

Rene Buergel rbuergel@HTWM.De
Sun Oct 21 21:50:00 GMT 2007


I don't know, if this list is appropriate, as this is a general 
C++-Question, but anyway...

I ran into some problems with the following Codepiece:

class Base
{
    protected:
        typedef void (Base::*FuncPtr)();

        virtual void func();
};

class Derived: public Base
{
    virtual void func();
    Derived()
    {
        FuncPtr p = &Base::func;
    }
};

g++ tells me, that i can't access it, because it is taken via Base. If 
the method wouldn't be virtual, it could be referenced as "&Derived::func".
Currently the only solution to me seems to make func public - which is 
not intended by design.
Are there other possibilities?



More information about the Gcc-help mailing list