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)
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
^^^^^^^
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};
}
精彩评论