C ++花式模板代码问题 [英] C++ fancy template code problem

查看:168
本文介绍了C ++花式模板代码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个(对我来说)相当复杂的模板代码结构:
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));
}

};

和类ShaderMatth,它也是泛型类型,并存储映射,而void *指针用作键实际上是一个指向ShaderProperty的指针。 ShaderMatth代码:

  #includeShaderProperty.h

struct IShaderMatth {
virtual〜IShaderMatth(){}
map< void *,IShaderMatth>属性;
...
};

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

现在错误发生在函数内联T的第一行T getValue()



我得到一个

 错误C2027使用未定义类型'ShaderMatth< ShadeType>'

但我不明白为什么..我有正向声明的模板struct ShaderMatth,



我挂了 - 请帮助:)

解决方案

转发声明 ShaderMatth 不足以使用代码 shaderMatth - >属性



必须在该行之前定义。


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 :)

解决方案

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

It must be defined before that line.

这篇关于C ++花式模板代码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆