2010-10-24 180 views
3

我不明白一個問題:使用枚舉

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 
    } 
}; 

禰錯誤:

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

你是否缺少.cpp文件?從你的列表中我看不到'First :: someFunc'調用的實際實現。 – wheaties 2010-10-24 18:14:28

+0

不可複製。什麼是'EnvironTypes'? – kennytm 2010-10-24 18:14:57

+0

編譯器在做什麼? – 2010-10-24 18:15:05

回答

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內聲明瞭枚舉嗎?

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

我可能完全bt後錯在解釋編譯錯誤,但

note: candidate is: void First::someFunc(First::SomeEnum) 
:如果是這樣,或者如果你不知道,只是試圖調用功能,在枚舉前puttung First::

引導我相信你聲明SomeEnum裏面的第一個定義

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