-1

これが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クラスと後続クラスの2つのクラスがありlibrary_cardます。なぜそれは私にそのようなエラーを与えるのですか?

4

2 に答える 2

7

交換

~library_card();

~library_card() {}

デストラクタを実装していません。これはまさにリンカが言っていることです。

または、このデストラクタが必要な理由がわからない場合は、この文字列を削除することもできます。

于 2012-06-15T10:08:23.007 に答える
0

の関数本体はありません~library_card();。そのデストラクタを削除するか、必要に応じて設定してください。

そこにいる間に、仮想デストラクタについて読んで、クラスでそれらが必要かどうかを検討してください。

于 2012-06-15T10:09:54.853 に答える