结构,数组错误C2512 我正在为我的C++课程做作业,我被卡住了。我已经跟随这本书,在互联网上寻找答案,但我没有找到答案。我需要在一个结构中有一个数组,它将向客户显示一份包含价格的早餐菜单。他们会选择他们想要的,当他们完成后,它会显示他们的账单。这是我到目前为止得到的,这并不是因为错误 #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; }

结构,数组错误C2512 我正在为我的C++课程做作业,我被卡住了。我已经跟随这本书,在互联网上寻找答案,但我没有找到答案。我需要在一个结构中有一个数组,它将向客户显示一份包含价格的早餐菜单。他们会选择他们想要的,当他们完成后,它会显示他们的账单。这是我到目前为止得到的,这并不是因为错误 #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; },c++,C++,你应该在main上面声明你的结构。然后把它称为 menuItemType* guestlist = new menuItemType(); 据我所知,这应该会有所帮助。请在问题中逐字添加错误消息。C2512对于非MVC编译器来说毫无意义;没有合适的默认构造函数availablemenuItemType::menuList是const,那么您希望如何在不给menuItemType显式构造函数的情况下初始化它?您正在为非指针分配新内存这既不是Java也不是CThank您的答案,这很有帮助。我将结构

你应该在main上面声明你的结构。然后把它称为

menuItemType* guestlist = new menuItemType();

据我所知,这应该会有所帮助。

请在问题中逐字添加错误消息。C2512对于非MVC编译器来说毫无意义;没有合适的默认构造函数availablemenuItemType::menuList是const,那么您希望如何在不给menuItemType显式构造函数的情况下初始化它?您正在为非指针分配新内存这既不是Java也不是CThank您的答案,这很有帮助。我将结构移到main之前,然后使用:menuItemType guestList;这就解决了问题。