views:

108

answers:

1

Hi!

I try to get a (for me) rather complex construct of templated code to work.

what i have: a class shaderProperty of generic type

class IShaderProperty {
public:
virtual ~IShaderProperty() {}
};

struct IShaderMatth; //forward declaration
template<typename ShadeType>
struct ShaderMatth;//forward declaration

template <typename T> 
class ShaderProperty : public IShaderProperty
{
public:

 template <typename SomeType>
 inline T getValue(ShaderMatth<SomeType>* shaderMatth){
 pair<map<void*, IShaderMatth>::iterator,bool> success = shaderMatth->properties.insert(make_pair((void*)this, ShaderMatth<T>(m_shader)));
 assert(success.second);
 return m_shader->shade((ShaderMatth<T>*)&(*success.first));
 }

};

and the class ShaderMatth, which is also of generic type, and stores a map whereas the void* pointer used as key is actually a pointer to a ShaderProperty. Code for ShaderMatth:

#include "ShaderProperty.h"

struct IShaderMatth {
 virtual ~IShaderMatth() {}
 map<void*, IShaderMatth> properties;
...
};

template <class ReturnType> 
struct ShaderMatth : public IShaderMatth{
 ShaderMatth(IShader<ReturnType>* shaderPtr){shader=shaderPtr};
 ~ShaderMatth(void);
 IShader<ReturnType>* shader;
};

now the error occurs on the first line of function inline T getValue()

i get an

Error C2027 use of undefined type 'ShaderMatth<ShadeType>'

but i don't understand why.. I have the forward declaration of templated struct ShaderMatth, and in the second bunch of code i include the first bunch of code, so the forward reference should work out, no?

I'm hanging - please help :)

+3  A: 

Forward declaring ShaderMatth is not enough to use the code shaderMatth->properties.

It must be defined before that line.

Shmoopty
Actually, while this is technically true and required by the standard, MSVC++ (which, judging by the error code, is what OP is using) is not quite this strict - it merely requires the type to be fully declared before the function can be instantiated. If you want to be at all portable, though, do as Shmoopty says; GCC is much less relaxed :)
moonshadow
Thanks! you guys are good :) to conclude the answer: in my case it was necessary to have the implementation of the functions in a separate file - then everything worked out fine!
Mat