Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using enumerations

Tags:

c++

enums

class

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)
like image 635
Max Frai Avatar asked Jul 23 '26 07:07

Max Frai


1 Answers

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
              ^^^^^^^
like image 143
Kiril Kirov Avatar answered Jul 25 '26 20:07

Kiril Kirov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!