テキスト ファイルを読み取り、User というオブジェクトのクラスにデータを格納するプログラムを作成しています。次に、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;
};
プッシュバックする関数は次のようになります
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(User) (&) (int, std:string, int, int) の呼び出しに一致する関数がありません」というエラーが表示されます
「メモ候補は : void MyList::push_back(type) [with type = User]」