【发布时间】:2013-06-10 12:21:45
【问题描述】:
为什么这段代码会给我一个链接器错误,我该如何解决?
架构 x86_64 的未定义符号:“operator==(foo const&, foo const&)”,引用自:main.old 中的 _main:未找到架构 x86_64 的符号
template<typename T>
class foo {
//friends get access to the private member t
friend bool operator==(const foo<T> &lhs, const foo<T> &rhs);
T t;
};
template<typename T>
bool operator==(const foo<T> &lhs, const foo<T> &rhs) {
return lhs.t == rhs.t;
}
int main(int,char**) {
foo<int> f1, f2;
if (f1 == f2)
;
return 0;
}
【问题讨论】: