C ++ Can I declare an object of a class as a pair data type?

1

Can an object of a class be declared as a pair data type in C ++? I have been searching but I have not found much, I have tried to apply it in my code but it does not come out, 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.

Thank you for your help, thank you

    
asked by AER 11.11.2018 в 15:27
source

1 answer

3

Your problem is that the first type of the pair is a reference. Since you can not create references and not assign them value, as you are using the default node constructor (constructor without parameters) the reference is not gaining value and the constructor fails.

Try this:

pair<Nodo&,char> nodo1{a, tag};
    
answered by 11.11.2018 / 19:53
source