1
为什么我在下面得到链接器错误?模板好友功能实例化
template<typename T, typename U>
class A {
public:
class B;
};
template<typename T, typename U>
class A<T, U>::B {
friend bool operator==(const B& b1, const B& b2);
};
template<typename T, typename U>
bool operator==(const typename A<T, U>::B& b1, const typename A<T, U>::B& b2) {
return true;
}
int main() {
A<char, int>::B b1;
A<char, int>::B b2;
if (b1 == b2) {
return 0;
} else {
return 1;
}
}
我得到的错误是:
Undefined symbols for architecture x86_64:
"operator==(A<char, int>::B const&, A<char, int>::B const&)", referenced from:
_main in test-qSCyyF.o
那么...我该如何解决它。 = P – fumoboy007
我认为这将是obvius :)我会更新。 – jrok
所以我不能有一个模板化的朋友函数,它是在类之外定义的? – fumoboy007