我有一个像这样的全局函数:
namespace X
{
namespace Y
{
template <R, ...T>
R foo(T&&... args)
{
R r(args...);
return r;
}
}
}
然后在另一个类A中,我想将此函数声明foo为的朋友A。所以我做了:
class A
{
template <R, ...T>
friend R X::Y::foo(T&&... args);
A(int x, int y){}
};
现在,我调用X::Y::foo<A>(4, 5)它编译失败,错误是 foo 无法访问A. 我无法理解错误,如何正确声明foo为朋友A?
提前致谢。