C ++ error no matching function for call to 'Node :: Node (point &, float &, Node &)'


I have an error in the code, precisely in the constructor, the compiler says that I am not passing the appropriate parameters, to put in context, this is the class that the constructor has, I only put the relevant functions to understand the doubt :

class Nodo {
    point punto_;
    float coste_;
    Nodo* nodopadre_;

    Nodo(point& a, float coste,Nodo *nodopadre);

This is the cpp

Nodo::Nodo(point& a, float& coste,Nodo *nodopadre):

Where the compiler error occurs, this is in another class:


                point p(c_a,++c_b); 
                float costtan=0;
                list<Nodo>::iterator it1 = inspectioned_nodes_.end();
                Nodo np(*it1);
                Nodo ns(p,costtan,np); //ERROR
                costtan= g_n(ns)+ heuristica1(ns); //nodos adyacentes, distancia=1



The error that comes to me:

error: no matching function for call to ‘Nodo::Nodo(point&, float&, Nodo&)’
                 Nodo ns(p,costtan,np);

Maybe it's because I need to overload the operator = in class Nodo ?, although I have a copy constructor in that class.

inspectioned_nodes_ is a list of objects Nodo

Help is appreciated. Thanks

asked by AER 20.11.2018 в 00:56

2 answers


The compiler is complaining with all the reason in the world. You have declared

Nodo( point& a, float coste, Nodo *nodopadre );

Your arguments are referencia a point , copia de float , puntero a Nodo . In the place where the error marks you, we have

Nodo np( *it1 );
Nodo ns( p, costtan, np ); //ERROR
  • You create a new instance of Nodo .
  • You pass by copy or by reference .
  • Simply change your line to

    Nodo ns( p, costtan, &np );

    By the way, something is wrong with your logic. If you do this, you will be saving a pointer to an automatic variable ... that will cease to exist when you exit the function, and you will have a pointer pointing to nowhere ... Do not want to do Nodo ns( p, costtan, &( *it1 ) ) ?

    answered by 20.11.2018 / 05:38

    The error that comes to me:

    error: no matching function for call to ‘Nodo::Nodo(point&, float&, Nodo&)’
                 Nodo ns(p,costtan,np);

    The error that comes to you is clear, concise and self-explanatory. Maybe you do not understand it because it's in English, I translate it to you:

    error: ninguna función coincide para llamar a ‘Nodo::Nodo(point&, float&, Nodo&)’

    And you mark Nodo ns(p,costtan,np); as point of the error, that instruction seems to be a call to the constructor of Nodo to create an instance called ns , let's see the constructors of Nodo :

    Nodo(point& a, float coste,Nodo *nodopadre);

    The Nodo class has a default constructor and a constructor that receives point& , float and Nodo * as arguments, that clearly does not match point& , float& and Nodo& that the compiler detects why the compiler detects those types? Let's review the conflicting instruction:

    Nodo ns(p,costtan,np);
  • The first argument p is defined as follows:

    point p(c_a,++c_b);
  • The second argument costtan is defined as follows:

    float costtan=0;
  • The third argument np is defined as follows:

    Nodo np(*it1);
  • Therefore p is type point , costtan is type float and np is type Nodo . To match the signature of the second constructor ( point&, float, Nodo * ), the first argument must go through a conversion (to reference) the second argument does not require conversion and the third argument does not match the type (a Nodo is not a Nodo * ) so this constructor is discarded.

    To solve the error, you must pass the expected types to the constructor.

    answered by 20.11.2018 в 09:33