1、error LNK2019: 無(wú)法解析的外部符號(hào)"struct ********"

一、C++ 錯(cuò)誤類型 :error LNK2019 無(wú)法解析的外部符號(hào)

:本人用的編譯器版本:VS2015

C++中報(bào) error LNK2019、LNK2001、......等類型的錯(cuò)誤,對(duì)剛接觸C++的同學(xué)來(lái)說(shuō)是一件非常令人頭疼的事情,因?yàn)樵斐纱祟悊?wèn)題的原因非常多,這里只講本人報(bào)錯(cuò)的一種原因。

二、報(bào)錯(cuò)截圖

50.jpg
51.jpg

三、報(bào)錯(cuò)原因

1、本人是因?yàn)楹瘮?shù)聲明 accumulate 與函數(shù)實(shí)現(xiàn)名 **acculate **稱不一致導(dǎo)致報(bào) error LNK2019 錯(cuò)。

2、在聲明函數(shù) accumulate(......) 的時(shí)候,未將該函數(shù)實(shí)現(xiàn),導(dǎo)致報(bào)錯(cuò),這是造成 error LNK2019 錯(cuò)誤原因的一種;

報(bào)錯(cuò)前的代碼:

1 free_throws& accumulate(free_throws& target, const free_throws& source);   // 函數(shù)聲明
2 
3  int main()    // 主函數(shù)
4  {
5      ...........
6  }
7 
8 free_throws& acculate(free_throws & target, const free_throws & source)   // 函數(shù)實(shí)現(xiàn)
9 { 
10      target.attempts += source.attempts; 
11      target.made += source.made; 
12      set_pc(target); 
13      return target; 
14 }

四、解決辦法

1.首先檢查所聲明的所有函數(shù)都有沒(méi)有實(shí)現(xiàn);

2.檢查聲明函數(shù)與實(shí)現(xiàn)函數(shù)的函數(shù)名、參數(shù)列表、返回值是否一致;

3.檢查后期自己是否有修改過(guò)函數(shù)名,導(dǎo)致聲明函數(shù)名與實(shí)現(xiàn)函數(shù)名不一致

修改后的代碼:

1 free_throws& accumulate(free_throws& target, const free_throws& source);   // 函數(shù)聲明
2 
3 int main()    // 主函數(shù)
4 {
5     ...........
6 }
7 
8 free_throws& accumulate(free_throws & target, const free_throws & source)   // 函數(shù)實(shí)現(xiàn)
9 { 
10     target.attempts += source.attempts; 
11     target.made += source.made; 
12     set_pc(target); 
13     return target;  
}

五、總結(jié)

此類錯(cuò)誤不太容易發(fā)現(xiàn),讀者在敲代碼時(shí)盡量細(xì)心,犯錯(cuò)之時(shí),要學(xué)會(huì)總結(jié),利用好手上的工具。

希望可以幫助到各位!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容