Can an object of a class be declared in C++ as the data type of a pair? I have been searching but I have not found much, I have tried to apply it in my code but it does not work, eg:
This is the code:
char tag ='A';
point p(p.get_x(),p.get_y());
Nodo a(p,0);
pair<Nodo&,char> nodo1; //donde me sale el error
nodo1.first = a;
nodo1.second= tag;
And this is the error:
error: no matching function for call to ‘std::pair<Nodo&, char>::pair()’
pair<Nodo&,char> nodo1;
^~~~~
I have declared all the necessary libraries.
help is appreciated, thanks
Your problem is that the first type of the pair is a reference. Since you cannot create references and not assign a value to them, since you are using the default constructor of node (constructor with no parameters) the reference is not getting a value and the constructor fails.
Try this: