Keith Stevens
Keith Stevens

Reputation: 41

Invalid redefinition error when passing a member enum variable to the class constructor

First I should say the code compiles fine without error outside of eclipse. Ran into this problem moving a project into eclipse Juno, CDT 8.1, gcc version 4.6.3

//This example code works:

 1. class TestThis {
 2.  public:
 3.     enum NUMBER { one, two };
 4.     TestThis();
 5.     int populate(enum NUMBER n);
 6. };

//This generates an error "invalid redefinition of 'NUMBER'" at line 3 before compile:

 1. class TestThis {
 2. public:
 3.     enum NUMBER { one, two };
 4.     TestThis(enum NUMBER n);
 5.     int populate();
 6. };

Question: Is there a way to "fix" CDT to allow passing an enum to a constructor? or if not is there some other work-around for this problem?

Upvotes: 3

Views: 2450

Answers (2)

Keith Stevens
Keith Stevens

Reputation: 41

I went to report the bug on eclipse CDT bugzilla and found it was already reported by Dominik Eichelberg (see Bug 385144) in July. Reading it gave me enough information for a work around. The issue does not occur if the enum variable is not the first argument to the constructor. Thank you everyone.

Upvotes: 1

Kerrek SB
Kerrek SB

Reputation: 477248

Say just this:

class TestThis
{
    enum NUMBER { one, two };
    TestThis(NUMBER n);
};

Your code is indeed re-declaring another enum NUMBER. This is no different from, say, void (struct Foo x);, which is actually a declaration of struct Foo.

Update: Multiple declarations are actually fine. Saying enum or struct again is possible, although probably not very pretty.

Upvotes: 4

Related Questions