类'不是模板类型' [英] Class 'is not a template type'

查看:112
本文介绍了类'不是模板类型'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误是什么意思?

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_; }

};

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

Is the problem that it subclasses other classes? I tried an experiment testing that theory, but it didn't produce this error.

编辑:好,所以一对你们指出我可以转发其他地方没有使它成为一个模板类。确实如此。

Ok, so a couple of you guys pointed out I could be forward declaring Generic elsewhere without making it a template class. That's true. And when I make it a template, I get another error.

Property.h:15:error:ISO C ++禁止没有类型的Generic声明

Property.h:15: error: ISO C++ forbids declaration of 'Generic' with no type

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);
};


推荐答案

我不知道这是你的问题,但您不能使用模板类将QObject子类化。

I'm not sure if this is your problem, but you can't subclass QObject with a template class.

有关详情。

这篇关于类'不是模板类型'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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