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