我願做一個拷貝構造函數和定義=運營商爲這個下面的類構造副本,列表指針和模板在C++
template <class S, class T>
class Graphe
{
protected:
int prochaineClef;
public:
PElement< Sommet<T> > * lSommets; // liste de sommets
PElement< Arete<S,T> > * lAretes; // liste d'arêtes
Graphe(const Graphe<S,T> & graphe);
const Graphe<S,T> & operator = (const Graphe<S,T> & graphe);
}
到目前爲止,我已經試過這大概構造:
template <class S, class T>
Graphe<S,T>::Graphe(const Graphe<S,T> & graphe)
{
PElement< Sommet<T> > * nouvelListeSommet = new PElement<Sommet<T>>(*graphe.lSommets);
PElement< Arete<S,T> > * nouvelListeAretes = new PElement<Arete<S,T>>(*graphe.lAretes);
this->prochaineClef = graphe.prochaineClef;
this->lAretes = nouvelListelAretes;
this->lSommets = nouvelListeSommet;
//nouvelListeSommet = graphe.lSommets->copieListe(graphe.lSommets);
//nouvelListelAretes = graphe.lAretes->copieListe(graphe.lAretes);
}
So i got this error saying
\visual studio 2012\projects\ihm\tp2graphe\tp2graphe\pelement.h(123): error C2664: 'PElement<T>::PElement(T *,PElement<T> *)' : can't convert param1 from 'PElement<T> *const ' to 'Sommet<T> *'
1> with
1> [
1> T=Sommet<InfoSommetCarte>
1> ]
1> and
1> [
1> T=Sommet<InfoSommetCarte>
1> ]
1> and
1> [
1> T=InfoSommetCarte
1> ]
這裏是我的P成分類:
class PElement
{
public :
T * v;
PElement<T> * s;
PElement(T * v, PElement<T> * s);
PElement(PElement<T> & l);
}
template<class T>
PElement<T>::PElement(PElement<T> & l)
{
//this->v = new T(l->v);
this = new PElement<T>(l,this);
}
我不知道如何解決我的拷貝構造函數P成分 is this-> v = new T(l-> v)是否正確?
這裏是我的錯copieListe方法:
/*
template<class T>
PElement<T> * PElement<T>::copieListe(PElement<T> * original)
{
for(int i = 0; i < PElement<T>::taille(original);i++)
{
this->insertionTete(original->v,this);
original = original->s;
}
return this;
}
*/
在你要複製的P成分列表中的拷貝構造函數初始化圖形。 – chmike 2015-02-23 14:21:00
準確完整地再現編譯器消息。標記與編譯器報告的行號對應的源代碼行。 – 2015-02-23 14:21:50
你需要下面的代碼:lSommets = copieListe(graphe.lSommets);.然後您需要提供copieListe方法/函數。它返回一個PElement < Sommet> *,它是鏈接列表的副本。 –
chmike
2015-02-23 14:29:10