Vector 在';之前应为非限定id';代币 我在C++上很新,所以跟我谈谈穴居人吧。我试图让代码在一个循环中运行,当循环完成时,计算总数和所有顺序。我遇到了这个错误,我不知道为什么
[错误]在“.”标记之前应为非限定idVector 在';之前应为非限定id';代币 我在C++上很新,所以跟我谈谈穴居人吧。我试图让代码在一个循环中运行,当循环完成时,计算总数和所有顺序。我遇到了这个错误,我不知道为什么,vector,dev-c++,Vector,Dev C++,[错误]在“.”标记之前应为非限定id #include <iostream> #include<string> #include <vector> using namespace std; string again; char pType, pSize, topping, temp; const int SMALL = 1; int type = 0, size = 0; const int MEDIUM = 2; const int LARGE = 3;
#include <iostream>
#include<string>
#include <vector>
using namespace std;
string again;
char pType, pSize, topping, temp;
const int SMALL = 1;
int type = 0, size = 0;
const int MEDIUM = 2;
const int LARGE = 3;
const int DEEPDISH = 1;
const int HANDTOSSED = 2;
const int PAN = 3;
double total = 0;
class Pizza
{
private:
int type;
int size;
bool cheese;
bool pepperoni;
public:
Pizza();
int getType();
int getSize();
bool getCheese();
bool getPepperoni();
void setType(int t);
void setSize(int s);
void setCheese(bool choice);
void setPepperoni(bool choice);
void outputDescription();
double computePrice();
};
class Order
{
private:
vector<Pizza> c;
public:
Order();
void customerOrder();
void customerTotal();
void customerinput();
};
Pizza::Pizza()
{
type = DEEPDISH;
size = SMALL;
cheese = pepperoni = false;
}
int Pizza::getType()
{
return type;
}
int Pizza::getSize()
{
return size;
}
bool Pizza::getCheese()
{
return cheese;
}
bool Pizza::getPepperoni()
{
return pepperoni;
}
void Pizza::setType(int t)
{
type = t;
}
void Pizza::setSize(int s)
{
size = s;
}
void Pizza::setCheese(bool choice)
{
cheese = choice;
}
void Pizza::setPepperoni(bool choice)
{
pepperoni= choice;
}
void Pizza::outputDescription()
{
switch (size)
{
case SMALL:
cout << "Small "; break;
case MEDIUM:
cout << "Medium "; break;
case LARGE:
cout << "Large "; break;
default:
cout << "Unknown" ;
}
switch (type)
{
case DEEPDISH:
cout << "deepdish "; break;
case HANDTOSSED:
cout << "hand tossed "; break;
case PAN:
cout << "pan "; break;
default:
cout << "Unknown";
}
cout << "pizza";
}
double Pizza::computePrice()
{
double cost = 0.0;
switch (size)
{
case SMALL:
cost += 10; break;
case MEDIUM:
cost += 14; break;
case LARGE:
cost += 17; break;
}
if (cheese)
cost += 2.0;
if (pepperoni)
cost += 2.0;
return cost;
}
Order custmizedTotal;
Pizza myPizza;
bool done=false;
void Order::customerinput(){
while ( again == "y"){
cout << "What sized pizza, please enter S, M OR L: ";
cin >> pSize;
cin.clear();
switch(pSize)
{
case 'S': case 's':
size = SMALL; break;
case 'M': case 'm':
size = MEDIUM; break;
case 'L': case 'l':
size = LARGE; break;
}
cout << "What type of pizza, enter D for Deepdish, H for Hand tossed, and P for Pan: ";
cin >> pType;
cin.clear();
switch(pType)
{
case 'D': case 'd':
type = DEEPDISH; break;
case 'H': case 'h':
type = HANDTOSSED; break;
case 'P': case 'p':
type = PAN; break;
}
myPizza.setSize(size);
myPizza.setType(type);
cout << "Would you like cheese (y/n)? ";
cin >> topping;
cin.clear();
if (topping == 'Y' || topping == 'y')
myPizza.setCheese(true);
cout << "Would you like pepperoni (y/n)? ";
cin >> topping;
cin.clear();
if (topping == 'Y' || topping == 'y')
myPizza.setPepperoni(true);
cout << endl
<< "Your order: ";
myPizza.outputDescription();
cout << endl;
cout << "Price: $" << myPizza.computePrice() << endl;
cout << "Again? (y/n)";
cin >> again;
}
}
void Order::customerTotal(){
cout << "Your Total order is: " << endl;
for(int i=0; i<c.size(); i++)
{
c[i].outputDescription();
cout << endl;
cout << c[i].computePrice();
cout << endl;
total=total+c[i].computePrice();
}
cout << "Totat Cost: $" << total;
cout << endl;
c.push_back(myPizza);
}
int main()
{
custmizedTotal.customerinput();
//Order.customerinput();
if(again != "y"){
custmizedTotal.customerTotal();
}
return 0;
}
#包括
#包括
#包括
使用名称空间std;
再串一次;
字符类型、pSize、顶部、温度;
常量int SMALL=1;
int type=0,size=0;
常数int中等=2;
常量int大=3;
常数int DEEPDISH=1;
const int handprowsted=2;
常数int PAN=3;
双倍合计=0;
高级披萨
{
私人:
int型;
整数大小;
布尔干酪;
波尔香肠;
公众:
比萨饼();
int getType();
int getSize();
bool getCheese();
bool getPepperoni();
void setType(int t);
无效设置大小(int s);
void setCheese(bool-choice);
void setPepperoni(bool choice);
void outputDescription();
双重计算价格();
};
阶级秩序
{
私人:
载体c;
公众:
订单();
void customerOrder();
void customerTotal();
void customerinput();
};
比萨饼
{
类型=深碟;
尺寸=小;
奶酪=辣香肠=假;
}
int::getType()
{
返回类型;
}
intpizza::getSize()
{
返回大小;
}
bool Pizza::getCheese()
{
返回奶酪;
}
波尔比萨饼::意大利辣香肠()
{
返回意大利香肠;
}
void Pizza::setType(int t)
{
类型=t;
}
void Pizza::设置大小(int s)
{
尺寸=s;
}
void Pizza::setCheese(布尔精选)
{
奶酪=选择;
}
void披萨:意大利辣香肠(波尔精选)
{
辣香肠=选择;
}
void Pizza::outputDescription()
{
开关(尺寸)
{
小案件:
不能替换
int main(){
Order.customerinput(); //error is here
if(again != "y"){
custmizedTotal.customerTotal();
}
return 0;
}
作者:
由于忘记定义订单构造函数而导致的第二个错误
将其添加到代码中(main()方法上方):
您还忘记添加customerOrder方法(但这不会导致错误,因为您没有使用此方法):
与“int main(){customizedtotal.customerTotal();}返回0;}一样,我应用了更改并收到错误。[error]ld返回了1个退出状态。消息为:未定义对`Order::Order()的引用'请共享您的全部代码…很难看到您已经做了什么以及您丢失了什么。现在它正在运行。但它不要求用户输入。好的。最初的问题已经解决。您在构建时遇到了问题,现在它已被修复…现在,您应该使用您的应用程序。进一步的问题,提出新的问题。请请求接受此问题的答案,因为此问题已得到回答。可能重复
int main(){
custmizedTotal.customerinput(); // Change this line
if(again != "y"){
custmizedTotal.customerTotal();
}
return 0;
}
Order::Order(){
// Set the initial values for order
}
void Order::customerOrder() {
}