Reputation: 31
I've got a special configuration to build and I don't know how to write this :
template <typename VarType>
class A
{
protected:
VarType m_myVar;
}
template <typename VarType>
class B : public A<VarType>
{
}
class C : public B<SpecialType>
{
void DoSomething()
{
m_myVar.PrivateFunction();
}
}
class SpecialType
{
private:
void PrivateFunction()
{
//Do something
}
}
How can I use the keyword friend to make it work ??
Thanks for your answers.
Upvotes: 0
Views: 147
Reputation: 2988
In an ideal world, you could perhaps write friend C::DoSomething();
inside the SpecialType class decl,
but alas no, your only option seems to be friend class C;
(as per nyrl)
friends and forward declarations of incomplete types doesn't play as nicely as we might hope.
Upvotes: 0
Reputation: 779
Just declare C
as friend of SpecialType
...
class SpecialType
{
private:
friend class C;
void PrivateFunction()
{
//Do something
}
};
Upvotes: 1