我试图将一个全局函数声明为一个类的“朋友”:
namespace first
{
namespace second
{
namespace first
{
class Second
{
template <typename T> friend T ::first::FirstMethod();
};
}
}
}
当我在 Visual C++ 2008 下编译这段代码时,我得到:
error C3254: 'first::second::first::Second' : class contains explicit override 'FirstMethod' but does not derive from an interface that contains the function declaration
error C2838: 'FirstMethod' : illegal qualified name in member declaration
如果我template <typename T> friend T first::FirstMethod();
改用,我会得到:
error C2039: 'FirstMethod' : is not a member of 'first::second::first'
声明友元函数的适当方式是什么?