Max Frai
Max Frai

Reputation: 64366

Using enumerations

I can't understand one problem:

Types.hpp:

enum SomeEnum { one, two, three };

First.hpp:

#include "Types.hpp"
class First
{
   public: void someFunc(SomeEnum type) { /* ... */ }
};

Second.hpp:

#include "Types.hpp"
#include "First.hpp"
class Second
{
   public: void Foo()
   {
      First obj;
      obj.someFunc(two); // two is from SomeEnum
   }
};

Thee error:

no matching function for call to ‘First::someFunc(SomeEnum)’
note: candidate is: void First::someFunc(First::SomeEnum)

Upvotes: 3

Views: 258

Answers (2)

Kiril Kirov
Kiril Kirov

Reputation: 38193

I think you just changed that:

no matching function for call to ‘First::someFunc(SomeEnum)’
note: candidate is: void First::someFunc(First::SomeEnum)

wasn't this:

no matching function for call to ‘First::someFunc(SomeEnum)’
note: candidate is: bool First::someFunc(First::SomeEnum)

Anyway, this changes the things. Is the enum declared inside class First ? If so, or if you don't know, just try to call the function, puttung First:: in front of the enum:

obj.someFunc( First::two ); // two is from SomeEnum
              ^^^^^^^

Upvotes: 2

user415715
user415715

Reputation:

I might bt totally wrong in interpreting the complier error but

note: candidate is: void First::someFunc(First::SomeEnum)

Leads me to believe that you declared SomeEnum inside First's definition

class First
{
    SomeEnum {one, two, three};
}

Upvotes: 1

Related Questions