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'
It's a void function how can I return int and how do I fix it?
Function is declared as int main(..); , so change your void return value to int , and return 0 at the end of the main function.
With C++ and C, the main function must be declared as an int, and therefore must return an int. In your code, you had changed the main function to a void, returning an error. Try changing void main() to int main() and add a line at the end of your function that returns 0.
These are errors generated when the executable of the program cannot be generated. This may be due to wrong function prototyping, incorrect header files. One of the most common linker error is writing Main() instead of main().
In C++ the default return type of main is void, i.e. main() will not return anything. But, in C default return type of main is int, i.e. main() will return an integer value by default. In C, void main() has no defined(legit) usage, and it can sometimes throw garbage results or an error.
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.
C++ requires main()
to be of type int
.
Function is declared as int main(..);
, so change your void
return value to int
, and return 0
at the end of the main function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With