If you have a namespaced-class and a template class defined like this:

namespace Frog
    class A

template<class T>
class B

Now suppose you wish the template class B to have access to private and protected members and methods of class A. Normally you’d add the following line of code to the declaration of class A:

template<class T> friend class B;

However, in this case the compiler may object when a method in class B tries to access protected or private areas in class A. In this case, your compiler is probably thinking that your template friend class B is actually in the namespace Frog, even if class B is declared globally and before Frog::A is declared.

To fix this, simply tell the compiler that class B falls in the global namespace, like this:

template<class T> friend class ::B;

Notice I just added a double colon (::) before B’s name.