2017-03-10 1 views
-4

Ich lese etwas, wo die Lösung etwas konstant machen würde, aber ich bin mir nicht sicher.Oder ich denke, dass ich vielleicht machen muss ein anderer Konstruktor? Auch bekomme ich "ld zurückgegeben 1 Exit-Status" als Fehler. Vielen Dank im Voraus für die Hilfe!Warum bekommt mein Code diesen Fehler zweimal "undefinierter Verweis auf 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

Bitte geben Sie Ihren Code ein. – bejado

+0

Bitte poste _less_ code, nämlich a ** [mcve] ** – Tas

Antwort

2

Sie erklärt den Konstruktor Pizza() aber es hat nicht umzusetzen. Implementieren Sie es oder deklarieren Sie es nicht, damit der Compiler für Sie den Standardkonstruktor generiert.

1

Sie deklarieren einen Konstruktor Pizza();, aber definieren Sie es nie. Wenn der Linker versucht, die impliziten Aufrufe an den Konstruktor aufzulösen, wenn Sie zwei Objekte Pizza instanziieren, kann es es nicht finden.

Versuchen Sie Pizza() = default;, wenn im Konstruktor nichts Besonderes zu tun ist.

Verwandte Themen