编译器错误 C3771
“标识符”: 在最近的命名空间范围内无法找到友元声明
无法在当前命名空间中找到指定模板的类模板声明 标识符 。
更正此错误
- 确保在当前命名空间中定义了模板标识符的类模板声明,或模板标识符是完全限定的名称。
示例
下列代码示例在 NA
命名空间中声明一个类模板和函数,但试图在 NB
命名空间中声明友元函数模板。
// C3771.cpp
// compile with: /c
namespace NA {
template<class T> class A {
void aFunction(T t) {};
};
}
// using namespace NA;
namespace NB {
class X {
template<class T> friend void A<T>::aFunction(T); // C3771
// try the following line instead
// template<class T> friend void NA::A<T>::aFunction(T);
// or try "using namespace NA;" instead.
};
}