I still can't get it to work..
After I had to separate implementation from definition of one of my generic classes because of a forward declaration, i now get Linker errors when trying to build.
IShader.h:
template <typename ShadeType>
class IShader {
public:
template <typename T>
bool getProperty(const std::string& propertyName, ShaderProperty<T>** outProp);
};
so it's a generic class with a generic member function with a different generic type
implementation looks like this:
#include "MRIShader.h"
template <typename ShadeType> template <typename T>
bool IShader<ShadeType>::getProperty(const std::string& propertyName, ShaderProperty<T>** outProp){
std::map<std::string, IShaderProperty* >::iterator i = m_shaderProperties.find(propertyName);
*outProp = NULL;
if( i != m_shaderProperties.end() ) {
*outProp = dynamic_cast<ShaderProperty<T>*>( i->second );
return true;
}
return false;
}
but i get Linker errors like this one:
error LNK2001: Nicht aufgelöstes externes Symbol ""public: bool __thiscall IShader<class A_Type>::getProperty<bool>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class ShaderProperty<bool> * *)" (??$getProperty@_N@?$IShader@VA_Type@@@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAPAV?$ShaderProperty@_N@@@Z)". SceneParser.obj
for bool, but also for many other types. I already read through this article: http://www.parashift.com/c++-faq-lite/templates.html
but adding
templace class IShader<bool>;
in the end of IShader.cpp doesn't solve the problem. I also tried to add the 'export' keyword before the keyword 'template' in the implementation, but this just gives me a syntax error.
What's the proper way to declare and implement my template class, which has templated member methods (with a different template type!) in separate files (.h and .cpp) without getting Linker errors?
thanks!