2016-03-08 84 views
0

我想为我的C++类做一个任务,并且卡住了。我跟踪了这​​本书,并在互联网上寻找答案,但没有达到答案。我需要在一个结构内部有一个数组,它会向客户显示一个含有价格的早餐菜单。他们会选择他们想要的东西,当他们完成时,它会显示他们的账单。这是迄今为止我所知道的,这并不是因为错误。结构,数组错误C2512

#include "stdafx.h" 
#include <iomanip> 
#include <iostream> 
#include <string> 


using namespace std; 


int main() 
{ 
cout << fixed << setprecision(2); 

const string menuList[9] 
{ "Plain Egg", "Bacon and Egg", "Muffin", "Frech Toast", "Fruit Basket",  "Cereal", "Coffee", "Tea" }; 

double prices[9] 
{1.45, 2.45, 0.99, 1.99, 2.49, 0.69, 0.50, 0.75}; 

struct menuItemType 
{ 
    const string menuList[9]; 
    double price; 
    double tax; 
}; 

menuItemType guestList; 

system("pause"); 
return 0; 
} 
+0

请在你的问题中逐字添加错误信息。对于非MVC编译器,_C2512_是非常没有意义的。 –

+0

错误C2512:'main :: menuItemType';没有适当的默认构造函数可用 – Raj

+0

'menuItemType :: menuList'是'const',所以你如何期待初始化它而不给'menuItemType'一个显式的构造函数? – jamesdlin

回答

0

你应该声明你的结构在main之上。然后称之为主

menuItemType* guestlist = new menuItemType(); 

从我所看到的这应该有所帮助。

+0

您正在将'new'内存分配给非指针(这既不是Java也不是C#) – crashmstr

+0

这是一个排字错误 –

+1

谢谢你的回答,它有帮助。我在main之前移动了结构,然后使用:menuItemType guestList();并修复它。 – Raj