c++ type/value mismatch at argument 1 in template parameter list

25,538

name is a templated class, so you must specify the template:

people<name<string>>* aPerson = new person<name<string>>();
Share:
25,538
user2972206
Author by

user2972206

Updated on July 09, 2022

Comments

  • user2972206
    user2972206 almost 2 years
    #include <iostream>
    using namespace std;
    
    template<class T>
    class people{
        public:
        virtual void insert(T item)=0;
        virtual T show(T info)=0;
    };
    
    template<class T>
    class name
    {
        private:
         T fname;
         T lname;
         public:
          name(T first, T last);
        //  bool operator== (name & p1, name &p2)
    };
    template <class T>
    name<T>::name(T first, T last){
        fname = first;
        lname = last;
    }
    template <class T>
    class person : public people<T>
    {
        private:
        T a[1];
        int size;
        public:
        person();
        virtual void insert(T info);
        virtual T show();
    };
    template<class T>
    person<T>::person(){
        size = 0;
    }
    template<class T>
    void person<T>::insert(T info){
        a[0] =info;
    }
    template<class T>
    T person<T>::show(){
          return a[0];
     }
    int main(){
        string first("Julia"), last("Robert");
        name<string> temp(first,last);
        people<name>* aPerson = new person();
        aPerson-> insert(temp);
        aPerson->show();
        return 0;
    }
    

    These are the errors I keep getting and I can't pinpoint what really is the problem:

    test.cpp:52: error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class people'
    test.cpp:52: error:   expected a type, got 'name'
    test.cpp:52: error: invalid type in declaration before '=' token
    test.cpp:52: error: expected type-specifier before 'person'
    test.cpp:52: error: expected ',' or ';' before 'person'
    test.cpp:53: error: request for member 'insert' in '* aPerson', which is of non-class type 'int'
    test.cpp:54: error: request for member 'show' in '* aPerson', which is of non-class type 'int'
    
  • yizzlez
    yizzlez over 10 years
    @user2972206 You're welcome! It would help everybody else as well if you mark this question as resolved.
  • John_West
    John_West over 8 years
    This code would end up with compiler error: '>>' should be '> >' within a nested template argument list
  • Brandlingo
    Brandlingo over 6 years
    @John_West >> is supported [stackoverflow.com/q/6695261/1969455](from C++11 on).
  • John_West
    John_West over 6 years
    @MatthäusBrandl No evidence for this beyond the link.
  • Brandlingo
    Brandlingo over 6 years
    @John_West N3337 14.2.3: [..] Similarly, the first non-nested >> is treated as two consecutive but distinct > tokens, [..]