I’m seeing two problems in a setup like this:
namespace ns1
{
class ParentClass
{
protected:
void callback();
};
}
namespace ns1
{
namespace ns2
{
class ChildClass : public ParentClass
{
public:
void method()
{
registerCallback(&ParentClass::callback);
}
};
}
}
- ChildClass::method() gives a compile error: “‘ns1::ParentClass::callback’ : cannot access protected member declared in class ‘ns1::ParentClass’“
ParentClass *pObj = new ChildClass()gives an error, that it can’t do the conversion without a cast. C++ can down-cast happily, no?
Change:
…to:
The reason is because &ParentClass::callback is a fully-qualified typename, not resolved from the context of ChildClass but from global context. In other words, it is the same problem as this: