I have an error in the code, precisely in the constructor, the compiler says that I am not passing the appropriate parameters, to put it in context, this is the class that has the constructor, I only put the relevant functions to understand the doubt:
class Nodo {
private:
point punto_;
float coste_;
Nodo* nodopadre_;
public:
Nodo();
Nodo(point& a, float coste,Nodo *nodopadre);
this is cpp
Nodo::Nodo(point& a, float& coste,Nodo *nodopadre):
punto_(a),
coste_(coste),
nodopadre_(nodopadre){}
Where the compiler error arises, this is in another class:
if((map.get(c_a,++c_b))!=1){
point p(c_a,++c_b);
float costtan=0;
list<Nodo>::iterator it1 = inspectioned_nodes_.end();
it1--;
Nodo np(*it1);
Nodo ns(p,costtan,np); //ERROR
costtan= g_n(ns)+ heuristica1(ns); //nodos adyacentes, distancia=1
ns.set_coste(costtan);
generated_nodes_.push(ns);
}
The error I get:
error: no matching function for call to ‘Nodo::Nodo(point&, float&, Nodo&)’
Nodo ns(p,costtan,np);
Maybe it's because I'm missing overloading the operator =
in the Nodo
? class, even though I have a copy constructor in that class.
inspectioned_nodes_
is a list of objectsNodo
Help is appreciated. Thank you
The compiler is complaining with every reason in the world. you have declared
Its arguments are
referencia a point
,copia de float
,puntero a Nodo
. In the place where the error marks you, we haveNodo
.Just change your line to
By the way, something is wrong with your logic. If you do it like this, you'll be saving a pointer to an automatic variable... which will cease to exist when you exit the function, and you'll have a pointer that points to nowhere... Won't you do
Nodo ns( p, costtan, &( *it1 ) )
?The error you get is clear, concise and self-explanatory. Maybe you don't understand it because it's in English, I'll translate it for you:
And it marks you
Nodo ns(p,costtan,np);
as the point of the error, that instruction seems to be a call to the constructor ofNodo
to create an instance calledns
, let's see the constructors ofNodo
:The class
Nodo
has a default constructor and a constructor that receivespoint&
,float
andNodo *
as arguments, that clearly does not matchpoint&
,float&
andNodo&
that the compiler detects. Why does the compiler detect those types? Let's review the conflicting statement:The first argument
p
is defined like this:The second argument
costtan
is defined like this:The third argument
np
is defined like this:Therefore it
p
is of typepoint
,costtan
it is of typefloat
andnp
it is of typeNodo
. To match the signature of the second constructor (point&, float, Nodo *
), the first argument must pass through a cast (to reference), the second argument does not require casting, and the third argument does not match the type (aNodo
is not aNodo *
) so that is discarded. builder.To fix the error, you'll need to pass the types it expects to the constructor.