【发布时间】:2015-01-28 07:22:27
【问题描述】:
由于某种原因,我的程序不会让我调用 main。我试图让程序重复,这样我就可以继续在 main 中添加东西,但它会假装 main 不存在并跳过它。
这是我的代码,我逐行跟踪它,即使我输入正确的信息,它也只是拒绝读取 int main();有什么想法吗?
编辑:我是个白痴。感谢您的帮助!
#include <iostream>
using namespace std;
,,,
int main()
{
// New OrderedList
OrderedList OrderedList;//no constructor called - is head initialized to NULL?
char repeat;
int choice = 0, data;
cout << "Choose from the following menu options,\n"
<< "1: Add an item\n"
<< "2: Search for an item\n"
<< "3: Delete an item\n"
<< "4: Display the list\n"
<< "5: Destroy the list\n";
cin >> choice;
if (choice <= 3)
{
cout << "\nPlease enter the item.";
cin >> data;
}
switch(choice)
{
case 1:
OrderedList.Insert(data);
break;
case 2:
OrderedList.Search(data);
break;
case 3:
OrderedList.Delete(data);
break;
case 4:
OrderedList.Print();
break;
case 5:
//delete OrderedList; "no constructor called - is head initialized to NULL?"
break;
}
cout << "Repeat Y/N?\n";
cin >> repeat;
if (repeat == 'y' || repeat == 'Y')
int main();
return 0;
}
【问题讨论】:
-
(1) 你没有调用main,你声明是:
int main();main()。您应该创建另一个函数。 -
调用main时删除“int”关键字。
-
本帖讨论调用
main():stackoverflow.com/questions/4518598/… -
请勿拨打
main,因为这是非法的。相反,请创建自己的Main并调用它。另外,避免不必要的递归,因为堆栈会沿着这条路径爆炸。
标签: c++ language-lawyer