I have code like this:
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!!
};
I have tried changing template<typename SceneT, int TYPE>
in the defination to template<typename SceneT, GeneratorType TYPE>
but ist still gives the exact same error. Any idea what is wrong and how to avoid this?
Note: This got compiled with c++11 (with -std=c++11 flag); but is failing otherwise. I am using gcc 4.9.2.
EDIT: The exact error I get is the following:
/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");
You are mixing a few things: if you want to use the enum as not type template parameter you need to specify it in template declaration, like this:
Now things can work provided you use
Device
and notGeneratorType::Device
. To use the latter form you need to declare GeneratorType as enum class