亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C++多態篇課上的一個例子運行出錯,關于抽象類的

C++多態篇課上的一個例子運行出錯,關于抽象類的

C++
BlueCitizen 2015-12-06 12:13:56
//Person類的定義 #ifndef?PERSON_H_ #define?PERSON_H_ using?namespace?std; #include?<string> class?Person{ public: ????Person(string?name); ????virtual?~Person(); ????virtual?void?work()?=?0; protected: ????string?m_strName; }; #endif//Person類的實現 #include?"Person.h" #include?<iostream> Person::Person(string?name) { ????m_strName?=?name; ????cout?<<?"Person()"?<<?endl; } Person::~Person() { ????cout?<<?"~Person"?<<?endl; }//Worker類的定義 #ifndef?WORKER_H_ #define?WORKER_H_ #include?"Person.h" class?Worker?:public?Person { public: ????Worker(string?name,int?age); ????virtual?~Worker(); ????//virtual?void?work(); protected: ????int?m_iAge; }; #endif//Worker類的實現 #include"Worker.h" #include?<iostream> Worker::Worker(string?name,int?age)?:Person(name) { ????m_iAge?=?age; ????cout?<<?"Worker()"?<<?endl; } Worker::~Worker() { ????cout?<<?"~Worker"?<<?endl; }//Dustman類的定義 #ifndef?DUSTMAN_H_ #define?DUSTMAN_H_ #include?"Worker.h" class?Dustman?:public?Worker { public: ????Dustman(string?name,int?age); ????~Dustman(); ????virtual?void?work(); }; #endif//Dustman類的實現 #include?"Dustman.h" #include?<iostream> Dustman::Dustman(string?name,?int?age)?:Worker(name,age) { ????cout?<<?"Dustman()"?<<?endl; } Dustman::~Dustman() { ????cout?<<?"~Dustman"?<<?endl; } void?Dustman::work() { ????cout?<<?"work()"?<<?endl; }//main函數 #include?<iostream> #include?"Dustman.h" #include?<stdlib.h> using?namespace?std; int?main(void){ ????Dustman?persn("jin",20); ????system("pause"); ????return?0; }編譯可以通過,但運行就會報錯,下面是所有的錯誤提示,點擊錯誤提示不能提示是哪一行出錯了,所以搞不明白哪兒錯了警告?? ?1?? ?warning LNK4042: 對象被多次指定;已忽略多余的指定?? ?E:\visual studio 2013\Projects\test\test\Debug\Dustman.obj?? ?1?? ?1?? ?test警告?? ?2?? ?warning LNK4042: 對象被多次指定;已忽略多余的指定?? ?E:\visual studio 2013\Projects\test\test\Debug\Person.obj?? ?1?? ?1?? ?test錯誤?? ?3?? ?error LNK2019: 無法解析的外部符號 "public: __thiscall Dustman::Dustman(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (??0Dustman@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z),該符號在函數 _main 中被引用?? ?E:\visual studio 2013\Projects\test\test\demo.obj?? ?test錯誤?? ?4?? ?error LNK2019: 無法解析的外部符號 "public: virtual __thiscall Dustman::~Dustman(void)" (??1Dustman@@UAE@XZ),該符號在函數 _main 中被引用?? ?E:\visual studio 2013\Projects\test\test\demo.obj?? ?test錯誤?? ?5?? ?error LNK1120: 2 個無法解析的外部命令?? ?E:\visual studio 2013\Projects\test\Debug\test.exe?? ?test
查看完整描述

1 回答

  • 1 回答
  • 1 關注
  • 1513 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號