使用枚举

时间:2010-10-24 18:11:58

标签: c++ class enums

我无法理解一个问题:

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)

2 个答案:

答案 0 :(得分:2)

我想你刚刚改变了:

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

不是这个:

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

无论如何,这改变了事情。枚举是在class First内声明的吗?如果是这样,或者如果您不知道,只需尝试在枚举前调用函数puttung First::

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

答案 1 :(得分:1)

在解释编译器错误时我可能完全错了,但是

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

让我相信你在First的定义中声明了一些Enum

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