C++ 错误:“::main”必须返回“int”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40381960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR: '::main' must return 'int'
提问by SPLASH
This my main function:
这是我的主要功能:
void main(int argc, char **argv)
{
if (argc >= 4)
{
ProcessScheduler *processScheduler;
std::cout <<
"Running algorithm: " << argv[2] <<
"\nWith a CSP of: " << argv[3] <<
"\nFilename: " << argv[1] <<
std::endl << std::endl;
if (argc == 4)
{
processScheduler = new ProcessScheduler(
argv[2],
atoi(argv[3])
);
}
else
{
processScheduler = new ProcessScheduler(
argv[2],
atoi(argv[3]),
atoi(argv[4]),
atoi(argv[5])
);
}
processScheduler -> LoadFile(argv[1]);
processScheduler -> RunProcesses();
GanntChart ganntChart(*processScheduler);
ganntChart.DisplayChart();
ganntChart.DisplayTable();
ganntChart.DisplaySummary();
system("pause");
delete processScheduler;
}
else
{
PrintUsage();
}
}
The error I get when I compile is this:
我编译时得到的错误是这样的:
Application.cpp:41:32: error: '::main' must return 'int'
Application.cpp:41:32: 错误:'::main' 必须返回 'int'
It's a void function how can I return int and how do I fix it?
这是一个 void 函数,我如何返回 int 以及如何修复它?
回答by Michael
Try doing this:
尝试这样做:
int main(int argc, char **argv)
{
// Code goes here
return 0;
}
The return 0;
returns a 0 to the operating system which means that the program executed successfully.
所述return 0;
返回一个0到操作系统,这意味着程序成功执行。
回答by Nick Pavini
C++ requires main()
to be of type int
.
C++ 要求main()
类型为int
.
回答by renonsz
Function is declared as int main(..);
, so change your void
return value to int
, and return 0
at the end of the main function.
函数被声明为int main(..);
,因此将void
返回值更改为int
,并return 0
在主函数的末尾。