static int index = 0;
class neighbor
{
public:
int dest ;
int weight;
neighbor(int d= 0, int w= 0);
};
template<typename T>
class vertexInfo
{
public:
enum vertexColor { white , grey , black } ;
typename map< T, int>:: iterator vtxMapLoc;
set<neighbor> edges;
vertexInfo();
// default constructor
vertexInfo(const map<T, int> :: iterator& iter)
{
// constructor with iterator pointing to a vertex in map
}
int inDegree;
};
template <typename T>
class graph
{
private:
typename map< T, int > :: iterator iter;
map <T,int> vtxMap;
vector<vertexInfo<T> > vInfo;
int numVertices;
int numedges;
stack<int> availStack;
int getvInfoIndex(graph<T>& , const T& v);
public:
void addEdge(graph<T>& , const T& , const T& , int);
set<T> get_Neighbor(graph<T>& , const T& v) ;
void show(graph<T>&);
};
template <typename T>
void graph<T> :: addEdge (graph<T> & g, const T& v1 , const T& v2, int w)
{
pair <map <char, int> :: iterator, bool> ret ;
ret = g.vtxMap.insert(pair <char, int >(v1, index));
if(ret.second)
{
index++;
g.vInfo.push_back(vertexInfo<T>(index));// Error -> 1
}
ret = g.vtxMap.insert(pair <char, int >(v2 , index));
if(ret.second)
{
index++;
g.vInfo.push_back(index)); // Error -> 2
}
}
Ich möchte "index"
Wert vInfo
Vektor drücken. Aber Fehler bekommen.keine passende Funktion für Aufruf
Error 1 - > `No matching function for call to 'vertexInfo<char>:: vertexInfo(Int&)`
Error 2 -> `No matching function for call to std :: vector <vertexInfo<char> , std :: allocator <vertexInfo<char> > > push_back(int&)`
Ich habe versucht, beiden Elemente durch Wege zu schieben, aber immer noch Fehler.
So entfernen Sie diesen Fehler ??
UPDATE :
Durch das Sehen der Antwort habe ich Körper des Codes aktualisiert. Hinzugefügt zwei Konstruktor
vertexInfo() //Default constructor
vertexInfo(const map<T, int> :: iterator& iter)
{
// constructor with iterator pointing to a vertex in map i.e. it is initializes the vtxMapLoc data member with the location of the vertex in the map.
}
aber nicht zu verstehen, wie Konstruktoren Körper zu schreiben.
Bitte geben Sie eine [MCVE] – Jonas