我已經定義了一個模板類,像這樣(提供.HPP文件):沒有調用模板類,C++
#ifndef PERSOANLVEC_H_
#define PERSOANLVEC_H_
#include <vector>
using namespace std;
template<class T, class PrnT> class PersoanlVec {
public:
PersoanlVec();
~PersoanlVec();
void push_back(T t);
void erase(int index);
PersoanlVec& operator[](int index);
const PersoanlVec& operator[](int index) const;
void print() const;
size_t size();
private:
vector<T> _vector;
};
#endif /* PERSOANLVEC_H_ */
現在,一切都OK編譯這個類。當我嘗試使用它時,我得到 undefined reference to PersoanlVec<Person, Person>::PersoanlVec()'
。 此處,我把它叫做:
#include "Person.h"
#include "PersoanlVec.hpp"
#include <cstdlib>
int main(void)
{
Person p1("yotam");
Person p2("yaara");
PersoanlVec<Person,Person> *a = new PersoanlVec<Person,Person>(); //<---ERROR HERE
return EXIT_SUCCESS;
}
這是我第一次嘗試使用模板,它不是對我來說很清楚明顯。我有沒有參數的構造函數,任何想法? 謝謝!
哇,我從來沒有見過這麼多*一致*拼寫錯誤。 – Puppy
「PersoanlVec」的實現在哪裏? (順便說一句,是它打算是'PersonalVec'?) –
@DeadMG:編碼助手有兩方面 –