5

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?

Michael
  • 2,758
  • 6
  • 28
  • 55
SPLASH
  • 95
  • 1
  • 1
  • 9

3 Answers3

8

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.

Michael
  • 2,758
  • 6
  • 28
  • 55
3

C++ requires main() to be of type int.

roottraveller
  • 6,328
  • 4
  • 50
  • 59
Nick Pavini
  • 313
  • 1
  • 12
1

Function is declared as int main(..);, so change your void return value to int, and return 0 at the end of the main function.

renonsz
  • 511
  • 1
  • 4
  • 16