Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板类中没有匹配的函数调用_C++ - Fatal编程技术网

C++ 模板类中没有匹配的函数调用

C++ 模板类中没有匹配的函数调用,c++,C++,我正在编写一个程序,它读入一个文本文件并将数据存储到一个名为User的对象类中。然后,我使用push_-back函数将用户对象存储到一个名为MyList的动态数组模板类中 目前我的MyList类如下所示 #ifndef MYLIST_H #define MYLIST_H #include <string> #include <vector> using namespace std; template<class type> class MyList { p

我正在编写一个程序,它读入一个文本文件并将数据存储到一个名为User的对象类中。然后,我使用push_-back函数将用户对象存储到一个名为MyList的动态数组模板类中

目前我的MyList类如下所示

#ifndef MYLIST_H
#define MYLIST_H
#include <string>
#include <vector>

using namespace std;

template<class type>
class MyList
{
public:
  MyList(); 
  ~MyList(); 
  int size() const;
  int at(int) const;
  void remove(int);
  void push_back(type);

private:
  type* List;
  int _size;
  int _capacity;
  const static int CAPACITY = 80;
};
MyList<User> object4;
用户类中的所有数据都有效

当前,我收到一个错误“调用'MyList::push_back(User)(&)(int,std:string,int,int)时没有匹配的函数”


“注意候选项是:void MyList::push_back(type)[with type=User]”

您声明了一个函数

User newuser(int id, string name, int age, int zip);
并尝试将此函数向后推到对象4上。但是
object4
被声明为

MyList<User> object4;

如果您有一个具有这些参数的构造函数。

我有一个用户对象,它定义为一个包含(int,name,int,int)的对象,那么我不应该使用这种格式将用户对象存储到MyList中吗?非常感谢!我真不敢相信我在这样一个小错误上花了一个小时。
User newuser(int id, string name, int age, int zip);
   object4.push_back(newuser);
User newuser(int id, string name, int age, int zip);
MyList<User> object4;
User newuser(id, name, age, zip);
object4.push_back(newuser);