首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

error LNK2001: unresolved external symbol "public: _thiscall Book:Book(void

2012-10-21 
error LNK2001: unresolved external symbol public: __thiscall Book::~Book(void)C/C++ code/*三、以下

error LNK2001: unresolved external symbol "public: __thiscall Book::~Book(void)"

C/C++ code
/*三、以下是图书类book的定义,但没有类的实现部分的代码,请根据类的定义编写类的实现部分的代码,并编写响应的程序对所定义的类进行测试。   Class book   {    char *name;  //书名    Char *author;  //作者    Int sale;  //销售量   Public    Book( );  //无参构造函数    Book(char,char,int);  //有参构造函数    Void disp( )  //输出数据    ~book( );  //析构函数   }*/#include<iostream>#include<string.h>using namespace std;class Book{public:    Book(){name="c_plus_plus",author="T_H_Q",sale=60000;};    Book(string name1,string author1,int sale1):name(name1),        author(author1),sale(sale1){;};    string get_name(){return name;};    string get_author(){return author;};    int get_sale(){return sale;};    void display();    ~Book();private:    string name;    string author;    int sale; };void Book::display(){    cout <<"name:";get_name();cout <<"\n";    cout <<"author:";get_author();cout <<"\n";    cout <<"sales:";get_sale();cout<<"\n";};int main(){    Book book1;    Book book2("math","H_S_Q",70000);    book1.display();    book2.display();    return 0;}


错误:Linking...
作业3.obj : error LNK2001: unresolved external symbol "public: __thiscall Book::~Book(void)" (??1Book@@QAE@XZ)
Debug/作业3.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

新手,不用讲得太高深,应该怎么改,谢谢了。

[解决办法]
析构函数只有声明没有定义,应该改为:
 ~Book(){;};
另外,输出部分也有问题(你可以试着输出看看),应改为:
cout <<"name:"<<get_name()<<"\n";
cout <<"author:"<<get_author()<<"\n";
cout <<"sales:"<<get_sale()<<"\n";

热点排行