2015-06-22 62 views
0

我有這樣的代碼:在認定中,以template<typename SceneT, GeneratorType TYPE>型enum-錯誤的NoType在模板的專業化:模板參數無效

enum GeneratorType 
    { 
    FILE_LIST, DEVICE 
    }; 

    template<typename SceneT, int TYPE> 
    class ODFrameGenerator 
    { 
    //... some APIS 
    }; 

    template<typename SceneT> 
    class ODFrameGenerator<SceneT, GeneratorType::DEVICE> 
    { 
    //...specialization: ERROR: template argument 2 is invalid 
    }; 

    template<typename SceneT> 
    class ODFrameGenerator<SceneT, 1> 
    { 
    //...specialization: compiles fine!! 
    }; 

我試圖改變template<typename SceneT, int TYPE>但仍北京時間給出確切的同樣的錯誤。任何想法什麼是錯的,以及如何避免這種情況?

注意:這是編譯與c + + 11(與-std = c + + 11標誌);但是否則失敗。我正在使用gcc 4.9.2。

編輯:確切的錯誤我得到的是以下幾點:

/home/sarkar/opendetection/common/utils/ODFrameGenerator.h:80:61: error: template argument 2 is invalid 
    class ODFrameGenerator<ODSceneImage, GeneratorType::DEVICE> 
                  ^
/home/sarkar/opendetection/common/utils/ODFrameGenerator.h:100:46: error: wrong number of template arguments (1, should be 2) 
    class ODFrameGenerator<ODScenePointCloud<> >, GeneratorType::DEVICE> 
              ^
/home/sarkar/opendetection/common/utils/ODFrameGenerator.h:28:9: error: provided for ‘template<class SceneT, int TYPE> class od::ODFrameGenerator’ 
    class ODFrameGenerator 
     ^
/home/sarkar/opendetection/examples/objectdetector/od_image_camera.cpp: In function ‘int main(int, char**)’: 
/home/sarkar/opendetection/examples/objectdetector/od_image_camera.cpp:28:67: error: template argument 2 is invalid 
    od::ODFrameGenerator<od::ODSceneImage, od::GeneratorType::DEVICE> frameGenerator("0"); 
                   ^
/home/sarkar/opendetection/examples/objectdetector/od_image_camera.cpp:28:83: error: invalid type in declaration before ‘(’ token 
    od::ODFrameGenerator<od::ODSceneImage, od::GeneratorType::DEVICE> frameGenerator("0"); 
+2

是您獲得的* exact *錯誤嗎?它是*完整*嗎? *未經編輯*? –

+0

@JoachimPileborg,我添加了我得到的確切的錯誤。 – krips89

回答

3

你混合幾件事情:如果你想使用枚舉不鍵入你需要在模板聲明中指定它的模板參數,像這樣:

template<typename SceneT, GeneratorType TYPE> 
class ODFrameGenerator 
{ 
    //... some APIS 
}; 

現在,事情可以工作只要你使用Device,而不是GeneratorType::Device。要使用後一種形式,您需要將枚舉類型聲明爲枚舉類

enum class GeneratorType 
{ 
    FILE_LIST, DEVICE 
}; 
+1

自從C++ 11以來,它也被允許通過enum_name :: enumerator來命名* unscoped *枚舉的枚舉器。一個* scoped *枚舉('enum class')不是必需的。這並不意味着當然沒有範圍枚舉的其他好處。 – dyp

+0

謝謝,使用DEVICE代替GeneratorType :: DEVICE解決了這個問題。現在,當我將'SceneT'專門化爲模板類的實例時,例如'類ODFrameGenerator >,DEVICE>'它說錯了模板參數的數目(1,應該是2)'(錯誤#2問題)。任何想法有什麼不對? – krips89

+0

我的不好,第二個錯誤是由於其他原因。謝謝你的幫助。 – krips89