gpt4 book ai didi

c++ - 类 'is not a template type'

转载 作者:IT老高 更新时间:2023-10-28 22:16:27 25 4
gpt4 key购买 nike

这个错误是什么意思?

Generic.h:25: error: 'Generic' is not a template type

这里是通用的。

template <class T>
class Generic: public QObject, public CFG, public virtual Evaluator {
Q_OBJECT
std::string key_;
std::vector<std::string> layouts_;
std::vector<std::string> static_widgets_;
std::map<std::string, std::vector<widget_template> > widget_templates_;
std::map<std::string, Widget *> widgets_;
int type_;
LCDWrapper *wrapper_;

protected:
LCDText *lcdText_;

public:
Generic(Json::Value *config, int type);
~Generic();
void CFGSetup(std::string key);
void BuildLayouts();
void StartLayout();
int GetType() { return type_; }
//T *GetLCD() { return lcd_; }
LCDText *GetLCDText() { return lcdText_; }
virtual void Connect(){};
virtual void SetupDevice(){};
std::map<std::string, Widget *> Widgets();
std::string CFG_Key();
LCDWrapper *GetWrapper() { return wrapper_; }

};

问题是它继承了其他类吗?我尝试了一个实验来测试该理论,但它没有产生这个错误。

编辑:好的,所以你们中的几个人指出我可以在其他地方向前声明 Generic 而不使其成为模板类。确实如此。当我把它变成一个模板时,我得到了另一个错误。

Property.h:15: 错误:ISO C++ 禁止声明没有类型的“通用”

template <class T>
class Generic;

class Property : public CFG {
Generic *visitor; // line 15
bool is_valid;
QScriptValue result;
Json::Value *expression;
public:
Property(const Property &prop);
Property(Generic *v, Json::Value *section, std::string name, Json::Value *defval);
~Property();
bool Valid();
int Eval();
double P2N();
int P2INT();
std::string P2S();
void SetValue(Json::Value val);
Property operator=(Property prop);
};

最佳答案

看看this similar question SO的其他地方。您是否有机会在某处前向声明 Generic,而不是作为模板类?

编辑:回答您的第二个错误...

@Steve Guidi 在本页其他地方的评论中解决了这个问题。既然您一直将 Generic 声明为模板类,那么您的 Property.h 的第 15 行是非法的,因为您以非模板形式使用 Generic。

您需要在第 15 行指定您正在使用的特化,例如

template <class T>
class Generic;

class Property : public CFG {
Generic<int> *visitor; // specialised use of Generic
bool is_valid;
QScriptValue result;
Json::Value *expression;
public:
Property(const Property &prop);
Property(Generic *v, Json::Value *section, std::string name, Json::Value *defval);
~Property();
bool Valid();
int Eval();
double P2N();
int P2INT();
std::string P2S();
void SetValue(Json::Value val);
Property operator=(Property prop);
};

关于c++ - 类 'is not a template type',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1590688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com