環境: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.objip
fatal error LNK1169: one or more multiply defined symbols foundclass
解決方法: 1.將比較函數定義爲內聯函數方法
2.將比較函數放在源文件中error
緣由未明。sort