Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
715 views
in Technique[技术] by (71.8m points)

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

#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'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

people<name<string>>* aPerson = new person<name<string>>();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...