Enums Error

Hi! I am new to C++ and i just started learning about Enumerations.So i made a very simple programme which uses enums, but every time i try to run it, its just giving me an error.(Using Code:Blocks)

Code:

#include <iostream>

using namespace std;

enum colors {RED, GREEN, BLUE};

int main()
{

colors color1, color2;
color1 = GREEN;
cout<<color1<<endl;


}
Last edited on
Works fine on cpp.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;

enum colors {RED, GREEN, BLUE};

int main()
{

colors color1, color2;
color1 = GREEN;
cout<<color1<<endl;


}


Click the wrench icon beside the code

What error is C::B giving?

and please use code tags for future posts
http://www.cplusplus.com/articles/jEywvCM9/
The errors:
1.Multiple defenition of 'main'
2.first defined here
3.ld returned 1 exit status
Do you have more than one main() in your code?
Or perhaps you have multiple files in your project, each with its own main()?
Yes i have 2 files with 2 mains. Is this the problem?
It is. The program starts execution from the main() function. If there are two of them, it cannot determine where to begin. But more simply, it is not valid. Remove or rename one of them.
Thanks! :)
Topic archived. No new replies allowed.