I'm trying to add a new object to a vector of objects of a class called Vertex, which has a constructor like this:
Vertex::Vertex(int x)
{
index=x;
next=NULL;
entry_time=0;
exit_time=0;
connections=0;
}
However, I think I can't put information directly into the vector,and believe I have to previously create an object of class Vertex, ascribe to it the information I want, and then add it to the vector by using
Graph::Graph(bool x, int y)
{
is_digraph=x;
order=y;
is_connected=false;
for(int i=0; i<order; i++)
{
Vertex vt(i+1);
v.push_back(vt);
}
}
But the error "no matching function for call to 'Vertex::Vertex()'" keeps popping up, as if I sent no integer as argument, even though I'm pretty sure that by declaring the object as "Vertex vt(i+1)" I'm sending an integer as the argument. What is my mistake?
A vector
requires that the type being stored has a default (no arg) constructor. This is necessary so that things like creating a vector with an initial known number of elements works. Your Vertex
doesn't have a default constructor to it is not suitable to be put in a vector
"as is".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.