2017-03-10 11 views
-4

解決策が何かを一定にしているところを読んでいますが、確信が持てません。別のコンストラクタ?また、「ldは1つの終了ステータスを返しました」というエラーを表示しています。助けを前にありがとう!なぜこのエラーが2回発生するのですか?「Pizza :: Pizza() 'への未定義の参照」

#include <iostream> 
using namespace std; 

const int SMALL = 0; 
const int MEDIUM = 1; 
const int LARGE = 2; 

const int DEEPDISH = 0; 
const int HANDTOSSED = 1; 
const int PAN = 2; 
class Pizza{ 
    public: 
    Pizza(); 
    void setSize(int); 
    void setType(int); 
    void setCheeseToppings(int); 
    void setPepperoniToppings(int); 
    void outputDescription(){ 
     cout<<"This pizza is: "; 
     if(size==0) 
     { 
     cout<<"Small, "; 
     } 
     else if(size==1) 
     { 
     cout<<"Medium, "; 
     } 
     else 
     { 
     cout<<"Large, "; 
     } 
     if(type==0) 
     { 
     cout<<"Deep dish "; 
     } 
     else if(type==1) 
     { 
     cout<<"Hand tossed "; 
     } 
     else 
     { 
     cout<<"Pan, "; 
     } 
     cout<<"with "<<pepperoniToppings<<" pepperoni toppings and "<<cheeseToppings<<" cheese toppings."<<endl; 
    }; 
    int computePrice() 
    { 
     int total; 
     if(size==0) 
     { 
     total= 10+(pepperoniToppings+cheeseToppings)*2; 
     } 
     else if(size==1) 
     { 
     total= 14+(pepperoniToppings+cheeseToppings)*2; 
     } 
     else 
     { 
     total= 17+(pepperoniToppings+cheeseToppings)*2; 
     } 
     return total; 
    }; 
    private: 
    int size; 
    int type; 
    int cheeseToppings; 
    int pepperoniToppings; 
}; 
void Pizza::setSize(int asize){ 
    size = asize; 
} 
void Pizza::setType(int atype){ 
    type=atype; 
} 
void Pizza::setCheeseToppings(int somegoddamncheesetoppings){ 
    cheeseToppings = somegoddamncheesetoppings; 
} 
void Pizza::setPepperoniToppings(int thesefuckingpepperonis){ 
    pepperoniToppings = thesefuckingpepperonis; 
} 

int main() 
{ 
Pizza cheesy; 
Pizza pepperoni; 

cheesy.setCheeseToppings(3); 
cheesy.setType(HANDTOSSED); 
cheesy.outputDescription(); 
cout << "Price of cheesy: " << cheesy.computePrice() << endl; 

pepperoni.setSize(LARGE); 
pepperoni.setPepperoniToppings(2); 
pepperoni.setType(PAN); 
pepperoni.outputDescription(); 
cout << "Price of pepperoni : " << pepperoni.computePrice() << endl; 
return 0; 
} 
+0

コードを投稿してください。 – bejado

+0

_less_コード、つまり** [mcve] **を投稿してください – Tas

答えて

2

コンストラクタPizza()を宣言しましたが、実装していません。どちらかを実装するか、コンパイラがデフォルトのコンストラクタを生成するように宣言しないでください。

1

コンストラクタPizza();を宣言しますが、決して定義しないでください。 2つのPizzaオブジェクトをインスタンス化するときに、リンカーが暗黙の呼び出しをコンストラクターに解決しようとすると、それを見つけることができません。

Pizza() = default;コンストラクタで行う必要がある特別なことがない場合は、試してください。

関連する問題