[gameprogrammer] How do you make a templated class a friend of a non templated class?

  • From: Alan Wolfe <alan.wolfe@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Wed, 14 Sep 2011 21:38:41 -0700

Hey there!

I have 2 classes such as below (defined in this order, but they can be
reversed if needed)

class A
{
...
};

template<class T>
class B
{
...
};

I need to make friend B a class of friend A but unfortunately i can't find
the right syntax.

If i put this in class A...

friend class B;

it gives me a compile error about class B saying "class template has already
been declared as a non-class template"

If instead, i put this in class A...

friend class B<class T>;

it gives me a syntax error at the "<"

Does anyone know what the right syntax is?  Google isn't helping much.

Thanks!

Other related posts: