I try to overload operator== of the template class which is inner for another template class.
template <typename T>
class Outer {
public:
template <bool IsConst>
class Inner {
public:
friend bool operator==(const Inner<true>&, const Inner<true>&);
};
Inner<true> get() {
Inner<true> ret;
return ret;
}
};
template <typename T>
bool operator==(const typename Outer<T>::template Inner<true>& first,
const typename Outer<T>::template Inner<true>& second) {
return true;
}
int main() {
Outer<int> var;
Outer<int>::Inner<true> inner = var.get();
bool result = inner == inner;
}
But the compiler refuses to compile my code, output the following:
Undefined symbols for architecture x86_64:
"operator==(Outer<int>::Inner<true> const&, Outer<int>::Inner<true> const&)", referenced from:
_main in main.cpp.o
How can I solve this problem?