怎么在QT中继承模板类
如何在QT中继承模板类templateclass T1class MCharTemplate : public MImageArrayT1{public:MCharTemp
如何在QT中继承模板类
template<class T1>
class MCharTemplate : public MImageArray<T1>
{
public:
MCharTemplate(int enoughWidth,int enoughHeight,int argOutRangeLength,MMemoryManager* myMemoryManager)
: MImageArray<T1>(enoughWidth,enoughHeight,argOutRangeLength,myMemoryManager)
{
}
~MCharTemplate()
{
if (this->data!=0)
delete [] this->data;
}
};
class MCharTemplate : public MImageArray<T1>//这里编译不通过,错误:'MCharTemplate' is not a template
[解决办法]感觉应该是模板定义的问题,跟Qt没关系。模板了解的不多,坐等大神吧
[解决办法]首先,Q_OBJECT这个用来定义QT元数据的宏不支持模板类,也就是不支持信号槽。
其次,是可以用模板类的。
MCharTemplate(int enoughWidth,int enoughHeight,int argOutRangeLength,MMemoryManager* myMemoryManager)
: MImageArray<T1>(enoughWidth,enoughHeight,argOutRangeLength,myMemoryManager)
{
}
这里调基类的构造函数,不需要加上<T1>, 移除即可编译通过