Using Enumerations

I can not 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
   }
};

Error:

no matching function for call toFirst::someFunc(SomeEnum)’
note: candidate is: void First::someFunc(First::SomeEnum)
+3
source share
2 answers

I think you just changed this:

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

did not have:

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

In any case, this changes things. Is enumeration declared inside class First? If yes, or if you don't know, just try calling the puttung function First::before listing:

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

I could be mistaken in interpreting the error, but

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

It makes me think that you declared SomeEnum inside the first definition

class First
{
    SomeEnum {one, two, three};
}
+1
source

Source: https://habr.com/ru/post/1771196/


All Articles