c++ 模板参数列表中参数 1 的类型/值不匹配

标签 c++ templates arguments type-mismatch

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

这些是我不断遇到的错误,我无法确定真正的问题所在:

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'

最佳答案

name 是一个模板类,所以你必须指定模板:

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

关于c++ 模板参数列表中参数 1 的类型/值不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19877896/

相关文章:

function - 如何将 Lua 函数传递给 C 函数并多次执行 Lua 函数?

c++ - 如何在链表中生成唯一ID?

c++ - 如何减少 x264 流式传输时的延迟

c++ - OpenCV 视频编辑?

方案,将 lambda 作为函数参数传递 - 需要帮助理解参数

stored-procedures - PL/SQL存储过程中的变量数目可变

c++ - 解析标识符但排除 BOOST Spirit 中的保留字

c++ - 如何使模板类成为类的友元?

c++ - 限制指针类型模板参数和覆盖模板化基类的虚方法

C++ 模板 : 'Instantiation of variable required here, but no definition is available'