我目前正试图让程序只发送选定的选项到字符串函数。但是,我收到一个错误 -从构造函数返回值的C++错误
“错误从构造函数返回值”。
我试图将其更改为breakstatement,但会打印“Starter ::::说明:价格”。那是我想要的。不过,如果我扩展我的菜单,确保主菜等等,它只会打印“入门:主菜:饮料:布丁:说明:价格”。这不是我想要的。
道歉放置菜单在构造函数中,我将杀青不久
category::category(){
_starter = "Starter";
_maincourse = "MainCourse";
_pudding = "Pudding";
_drink = "Drink";
_itemDescription = "Item Description";
_price = "Price";
cout << "Menu\n====\n" << endl;
cout << "(1) Starter\n(2) Main Course "
"items\n(3) Pudding.\n(4)Drink\n(5) End program\n" << endl;
cout << "Select: ";
char ch;
cin >> ch;
cin.ignore(100, '\n');
cout << endl;
switch(ch) {
case '1':
cout << "Item Description: ";
getline(cin,_itemDescription);
cout << "Price: ";
getline(cin,_price);
return;
}
而且_starter将进入一个函数的ToString()
string category::tostring() {
string record = _starter + ":" + _maincourse + ":" + _pudding + ":" + _drink + ":" + _itemDescription + ":"+ _price;
这是一个很好的选择,它将是一个cast操作符。这样你就可以模拟返回构造函数的值几乎100%。 – AnArrayOfFunctions 2015-04-06 14:07:45
我想创建另一个类,例如:'ref class Static Properties {static int returnvalue; Public:static属性int static_return;}'或者在'public class'中有'int returnvalue;'我有starters的属性等吗? – Prymz 2015-04-06 14:58:05
只要你不试图从构造函数或析构函数中返回一个值,这真的取决于你。 – rsethc 2015-04-07 02:51:56