Class 'is not a template type'

前端 未结 7 1955
暗喜
暗喜 2021-01-07 21:54

What does this error mean?

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

Here\'s Generic.

template 

        
相关标签:
7条回答
  • 2021-01-07 22:23

    might be that Generic is already defined somewhere else?

    0 讨论(0)
  • 2021-01-07 22:28

    Your problem is that you are defining visitor of type Generic with no template param.

    When you forward declared the class as Generic then at line 15 the compiler found the declaration. But when you changed the declaration with template then the class Generic is no longer found.

    So, you should do something like:

    template <class T>
    class Generic;
    
    class Property : public CFG {
        Generic<SomeType> *visitor; // line 15
    

    or

    template <class T>
    class Generic;
    
    template <class T>
    class Property : public CFG {
        Generic<T> *visitor; // line 15
    

    or something like that.

    0 讨论(0)
  • 2021-01-07 22:32

    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);
    };
    
    0 讨论(0)
  • 2021-01-07 22:34

    Aside from the issue that you are not defining the template class correctly (thus your error message), you cannot use a Q_OBJECT in a template class. See http://doc.trolltech.com/qq/qq15-academic.html for details.

    0 讨论(0)
  • 2021-01-07 22:38

    Is that error generated by C++ compiler, or by Qt MOC? It might be that you can't actually apply Qt MOC on a template class.

    0 讨论(0)
  • 2021-01-07 22:39

    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.

    0 讨论(0)
提交回复
热议问题