Original Post
This has been bugging me lately... Let's say I have 3 classes: EDIT: changed private to protected in base, TestFriend* with tpl* in BaseTpl, added more members, replaced A with TestFriend
template <tpl>
class BaseTpl<tpl>
{
BaseTpl(tpl* owner) { pOwner = owner; }
protected:
tpl* pOwner;
}
class InheritTpl : public BaseTpl<TestFriend>
{
void doStuff()
{
pOwner->f(); //COMPILE ERROR - cannot access private member
pOwner->m_i = 0; //COMPILE ERROR - cannot access private member
}
}
class ManyStates<tpl>
{
ManyStates(tpl parent) { m_states[0] = new InheritTpl(parent); }
BaseTpl<tpl>* m_states[];
}
class TestFriend
{
template<class> friend class BaseTpl;
ManyStates m_StateMachine;
TestFriend() : m_StateMachine(this) { }
protected: //tried private: too
void f();
int m_i;
}
So, is there any restriction on friend classes when using inheritance? Or is it some kind of compiler weirdness? I'm using CodeWarrior, which may increase the likelihood of the latter. [Edited by - Ilici on March 4, 2009 8:39:14 AM]