我想将模板类的成员函数声明为友元。但我收到了警告消息,例如
warning: dependent nested name specifier 'Schedule<T>::' for friend class declaration is not supported; turning off access control for 'Manager' [-Wunsupported-friend]
我的代码如下
template<typename T>
class Task{};
template<typename T>
class Schedule {
public:
void dispatch(Task<T>*) {}
};
class Manager {
template<typename T>
friend class Task;
template<typename T>
friend void Schedule<T>::dispatch(Task<T>*); // <== Warning here!!!!
template<typename T>
friend int ticket() {
return ++Manager::count;
}
static int count;
};
导致此警告的原因是什么以及如何修复它?
这是您在使用 LLVM 中未完全实现的功能时收到的警告。
来自LLVM源代码:
/// True if this 'friend' declaration is unsupported. Eventually we
/// will support every possible friend declaration, but for now we
/// silently ignore some and set this flag to authorize all access.
unsigned UnsupportedFriend : 1;
如果您不担心授予的“所有访问权限”,您可以安全地忽略该警告。