繁体   English   中英

C ++中的致命错误LNK1120

[英]Fatal error LNK1120 in C++

那是我用C ++(OOP)编写的程序:

#include <iostream>
#include <string>

using namespace std;

class  book {
    string name,gvari;
    double cost;
    int year;

    public:
        book(){};

        book(string a, string b, double c, int d) { a=name;b=gvari;c=cost;d=year; }
        ~book() {}
        double setprice(double a) { return a=cost; }
        friend ostream& operator <<(ostream& , book&);
        void printbook(){
            cout<<"wignis saxeli "<<name<<endl;
            cout<<"wignis avtori "<<gvari<<endl;
            cout<<"girebuleba "<<cost<<endl;
            cout<<"weli "<<year<<endl;
        }
};

ostream& operator <<(ostream& out, book& a){
    out<<"wignis saxeli "<<a.name<<endl;
    out<<"wignis avtori "<<a.gvari<<endl;
    out<<"girebuleba "<<a.cost<<endl;
    out<<"weli "<<a.year<<endl;
    return out;
}

class library_card : public book {
    string nomeri;
    int raod;

    public:
        library_card(){};
        library_card( string a, int b){a=nomeri;b=raod;}
        ~library_card();
        void printcard(){
            cout<<"katalogis nomeri "<<nomeri<<endl;
            cout<<"gacemis raodenoba "<<raod<<endl;
        }
        friend ostream& operator <<(ostream& , library_card&);
};

ostream& operator <<(ostream& out, library_card& b) {
    out<<"katalogis nomeri "<<b.nomeri<<endl;
    out<<"gacemis raodenoba "<<b.raod<<endl;
    return out;
}


int main() {
    book A("robizon kruno","giorgi",15,1992);
    library_card B("910CPP",123);
    cout<<A;
    cout<<B;
    A.setprice(15);
    cout<<B;

    system("pause");
    return 0;
}

//P.S.
//B.printcard();
//A.printbook();
// As I've overloaded the "<<" operators, I've removed these two lines and put "cout<<A" "cout<<B". I hope, I'm right. By the way, error isn't related to these ones.

这是错误,可能对您有帮助:

1>Neyw.obj : error LNK2019: unresolved external symbol "public: __thiscall library_card::~library_card(void)" (??1library_card@@QAE@XZ) referenced in function _main
1>c:\users\geo\documents\visual studio 2010\Projects\Newww\Debug\Newww.exe : fatal error LNK1120: 1 unresolved externals

1>Build FAILED.

问题是我无法弄清楚代码出了什么问题。有两个类,主要的一个是book ,其后继的类是library_card 为什么会给我这样的错误?

更换

~library_card();

~library_card() {}

您尚未实现析构函数,而这正是您的链接器所说的。

或者,如果您不知道为什么需要此析构函数,也可以删除此字符串。

~library_card();没有函数体~library_card(); 只需删除该析构函数,或随意填充它即可。

当您在那里时,请阅读有关虚拟析构函数的文章 ,并考虑您的类是否需要它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM