Use of pointer to protected member function won't compile in 3.4.4

Paul Dubuc pdubuc@cas.org
Tue Jul 12 21:47:00 GMT 2005


This code will compile with g++ 3.3.4, but 3.4.4 gives me the following error:

Test.cc: In member function `const char* Derived::getCharge() const':
Test.cc:18: error: `char* Base::makeCharge_(const char*) const' is protected
Test.cc:31: error: within this context

Why can't the Derived class use a pointer to it's Base class' protected member 
function?  Is this a bug in 3.4.4, or is this no longer allowed?

Help!

Here's the code:

class Base {

protected:

     const char * getAttr_(unsigned char type,
         char * (Base::*pf)(const char *) const) const;

     char * makeCharge_(const char *) const;
};

const char * Base::getAttr_(unsigned char type,
     char * (Base::*pf)(const char *) const) const
{
     return 0;
}

char * Base::makeCharge_(const char * ptr) const
{
     return 0;
}

class Derived : public Base {

public:

     const char * getCharge() const;
};

const char * Derived::getCharge() const
{
     return(getAttr_(0, &Base::makeCharge_));
}


-- 
Paul M. Dubuc

"It is not enough to do your best; you must know what to do, and THEN do your
best." -- W. Edwards Deming



More information about the Gcc-help mailing list