1. 程式人生 > >c++編譯中出現‘vtable for ***未定義的引用解決辦法

c++編譯中出現‘vtable for ***未定義的引用解決辦法

class Brass:public AcctABC
{<span style="font-family: Arial, Helvetica, sans-serif;"> </span>
private:
public:
        Brass(const std::string & s="Nullbody",long an=-1,
                double bal=0.0):AcctABC(s,an,bal){}
        virtual void Withdraw(double amt);
        virtual void ViewAcct()const;
        virtual ~Brass(){}
};
出現錯誤/tmp/ccytx9fA.o:在函式‘Brass::Brass(std::string const&, long, double)’中:

usebrass3.cpp:(.text._ZN5BrassC2ERKSsld[_ZN5BrassC5ERKSsld]+0x37):對‘vtable for Brass’未定義的引用

collect2: error: ld returned 1 exit status

關鍵字‘vtable for(虛擬函式)

解決辦法查詢相關虛擬函式時候已經寫好功能函式。拿上面例子來說也就是說查詢

    virtual void Withdraw(double amt);
    virtual void ViewAcct()const;
這兩個函式是否已經申明。樓主找完以後發現是
   virtual void Withdraw(double amt);
這個函式沒寫補充結束問題得以解決
void Brass::Withdraw(double amt)
{
        if(amt<0)
                cout<<"Withdrawal amount must be positive;"
                <<"withdrawal canceld.\n";
        else if(amt<=Balance())
                AcctABC::Withdraw(amt);
        else
                cout<<"Withdrawal amount of $:"<<amt<<" exceeds your balance.\n"
                        <<"Withdrawal canceled.\n";
}


華麗麗分割線-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------