作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
<分区>
以下代码是重现我的问题的最少代码。当我尝试编译它时,链接器找不到 Config
的 operator==
:
Undefined symbols for architecture x86_64:
"operator==(Config<2> const&, Config<2> const&)", referenced from:
_main in test2.o
operator==
是Config
的 friend 。但是当我不再将 operator==
声明为 friend 时,代码编译器没有错误。
template <int DIM>
class Config{
// comment the following line out and it works
friend bool operator==(const Config<DIM>& a, const Config<DIM>& b);
public:
int val;
};
template <int DIM>
bool operator==(const Config<DIM>& a, const Config<DIM>& b){
return a.val == b.val;
}
int main() {
Config<2> a;
Config<2> b;
a == b;
return 0;
}
这里有什么问题?
我是一名优秀的程序员,十分优秀!