求教 LINK2005有关问题 多谢
求教 LINK2005问题 谢谢?
15.obj : error LNK2005: "public: __thiscall Item_base::Item_base(class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > const &,double) " (??0Item_base@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@s
td@@N@Z) already defined in Base_item.obj
15.obj : error LNK2005: "public: virtual double __thiscall Item_base::TotalPrice(unsigned int)const " (?TotalPrice@Item_base@@UBENI@Z) already defined in Base_item.obj
15.obj : error LNK2005: "public: class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > __thiscall Item_base::Get_isbn(void)const " (?Get_isbn@Item_base@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@
std@@XZ) already defined in Base_item.obj
Base_item.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall Item_base::~Item_base(void) " (??1Item_base@@UAE@XZ)
15.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall Item_base::~Item_base(void) " (??1Item_base@@UAE@XZ)
Debug/15.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
请问这是什么问题? 好像常发生,特别是有多个文件时
------解决方案--------------------
上面的提示说是找不到函数的实现体.
.h 即头文件一般是用来被别的 .c/.cpp 文件包含, 编译器可通过它找到在其中声名的函数的实现体.
------解决方案--------------------
模版类,把声明和定义放在一个文件内(.h)
15.obj : error LNK2005: "public: __thiscall Item_base::Item_base(class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > const &,double) " (??0Item_base@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@s
td@@N@Z) already defined in Base_item.obj
15.obj : error LNK2005: "public: virtual double __thiscall Item_base::TotalPrice(unsigned int)const " (?TotalPrice@Item_base@@UBENI@Z) already defined in Base_item.obj
15.obj : error LNK2005: "public: class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > __thiscall Item_base::Get_isbn(void)const " (?Get_isbn@Item_base@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@
std@@XZ) already defined in Base_item.obj
Base_item.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall Item_base::~Item_base(void) " (??1Item_base@@UAE@XZ)
15.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall Item_base::~Item_base(void) " (??1Item_base@@UAE@XZ)
Debug/15.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
请问这是什么问题? 好像常发生,特别是有多个文件时
------解决方案--------------------
上面的提示说是找不到函数的实现体.
.h 即头文件一般是用来被别的 .c/.cpp 文件包含, 编译器可通过它找到在其中声名的函数的实现体.
------解决方案--------------------
模版类,把声明和定义放在一个文件内(.h)