我讀了一些解決方案將使東西不變但我不確定的東西。或者我認爲我可能需要製作另一個構造函數?另外我得到「ld返回1退出狀態」作爲錯誤。先謝謝您的幫助 !爲什麼我的代碼得到這個錯誤兩次「未定義的參考」披薩::披薩()'「
#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;
}
請張貼您的代碼。 – bejado
請發佈_less_ code,即** [mcve] ** – Tas