我正在编写一个程序,它读取一个文本文件并将数据存储到一个名为 User 的对象类中。然后,我将 User 对象存储到一个名为 MyList 的动态数组模板类中,并带有 push_back 函数。
目前我的 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;
};
并且推回的功能看起来像这样
template<class type>
void MyList<type>::push_back(type newfriend)
{
    if( _size >= _capacity){
         _capacity++;
    List[_size] = newfriend;
        size++;
    }
}
我的用户类如下
#ifndef USER_H
#define USER_H
#include "mylist.h"
#include <string>
#include <vector>   
using namespace std;
class User
{
public:
  User();
  User(int id, string name, int year, int zip);
  ~User();
private:
  int id;
  string name;
  int age;
  int zip;
  MyList <int> friends;
};
#endif
最后,在我的主函数中,我像这样声明用户 MyList
MyList<User> object4;
我对 push_back 的调用如下
User newuser(int id, string name, int age, int zip);
   object4.push_back(newuser);
User 类中的所有数据都是有效的,
目前我收到一个错误“没有匹配函数调用'MyList :: push_back(用户)(&)(int,std:string,int,int)”
“注意候选人是:void MyList::push_back(type) [with type = User]”