Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'is not a template type'

Tags:

c++

templates

What does this error mean?

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

Here's Generic.

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.

Edit: 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++ 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);
};
like image 512
Scott Avatar asked Oct 19 '09 19:10

Scott


People also ask

Is class a template?

Class template. is a template used to generate template classes. You cannot declare an object of a class template.

Is class A template C++?

A powerful feature of C++ is that you can make ​template classes​ which are ​classes ​that can have ​members ​of the ​generic​ type, i.e., members that use template parameters as types. The template class that we have defined above serves to store elements of any valid type.

Can template be used for class?

A template is not a class or a function. A template is a “pattern” that the compiler uses to generate a family of classes or functions.

Is class an object template?

A class is a template for creating a particular form of object. A Java class definition corresponds to a C++ struct definition generalized to include all of procedures that process objects of the defined class. In Java, all program code must be part of some class.


2 Answers

Take a look at this similar question elsewhere on SO. Are you by any chance forward-declaring Generic somewhere, and not as a templated class?

EDIT: In answer to your second error...

@Steve Guidi has solved this problem in his comment elsewhere on this page. Now that you've consistently declared Generic as a templated class, line 15 of your Property.h is illegal because you're using Generic in an untemplated form.

You need to specify the specialization you're using on line 15, e.g.

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);
};
like image 154
razlebe Avatar answered Oct 08 '22 16:10

razlebe


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

Here is more information about that.

like image 25
Gaston Avatar answered Oct 08 '22 14:10

Gaston