vs2010下sort比较函数链接错误问题

环境:win7 + vs2010 + C++

实现vector的sort算法,在类的头文件中写入比较函数时会出现链接错误:

error LNK2005: "bool __cdecl compare_index(class TestIndex const *,class TestIndex const *)" (?compare_index@@YA_NPBVTestIndex@@0@Z) already defined in main.obj

fatal error LNK1169: one or more multiply defined symbols found

解决方法: 1.将比较函数定义为内联函数

               2.将比较函数放在源文件中

原因未明。

posted @ 2013-11-13 12:45  杨溪  阅读(435)  评论(0编辑  收藏  举报