template <class T>class vector{ //this is the part for my vector, which may lead to the error shown below.
protected:
T* arr;
void expand(){
if(size<capacity)return;
if(capacity<con)capacity=con;
T* temp=new T[capacity=2*capacity];
for(int i=0;i<size;i++)temp[i]=arr[i];
delete[] arr;
arr=temp;
temp=NULL;
};
public:
vector(int c=con,int s=0,T v=0){arr=new T[capacity=c];for(size=0;size<s;arr[size++]=v);}
T& operator[](int r)const{return arr[r];}
int insert(int r,const T& e){ //inserting at designated place.
expand();
for(int i=size;i>r;i--)arr[i]=arr[i-1];
arr[r]=e;
size++;
return r;
}
int insert(const T& e){ //inserting at the end
return insert(size,e);
}
};
template<class Tv>class vertex{
public:
Tv data;
vertex(Tv const& e):data(e){}
};
template<class Tv,class Te>class GraphMatrix{
private:
vector<vertex<Tv> > v;
public:
int insert(Tv const& vt){
return v.insert(vertex<Tv>(vt)); //error happens here "expected primary-expression before '>' token."
}
}
int main(){
GraphMatrix<int,int> mail;
int i=1;
mail.insert(i);
}
私はg ++コンパイラを使用していますが、 "> 'token'の前に予期したprimary-expressionがあります。 テンプレートに関して問題がありますか?どうすれば修正できますか? 問題は、私が書き込んだベクトル(自分自身のベクトル)に頂点(vt)を挿入するときに発生します。それはエラーなしで(GCC、-fsyntax-only -std=c++98 -Wall -Wextra
)をコンパイル'>'トークンの前にテンプレートエラーが予期される
https://stackoverflow.com/help/mcve – zwol
2番目のエラーは**カスケード**から発生します。最初のものは 'vertex p'の' vertex 'の使用に関するものです。それが失敗すると 'p'は意味をなさない。だから無視してください。あなたが最初のものを修正したら、それはほとんどなくなります。 –
申し訳ありません私はそれを明確にするためにいくつかの変更を行いました。 – jombo