参见英文答案 >
What should main() return in C and C++? 18个
这是我的主要功能:
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();
}
}
我编译时得到的错误是这样的:
Application.cpp:41:32: error: ‘::main’ must return ‘int’
这是一个void函数如何返回int以及如何修复它?
试着这样做:
int main(int argc, char **argv)
{
// Code goes here
return 0;
}
返回0;返回0到操作系统,这意味着程序执行成功.