X
X
Xtone2020-05-21 21:31:17
C++ / C#
Xtone, 2020-05-21 21:31:17

How to assign a pair?

Can you explain to me why this doesn't compile?

pair<const string, int> p1("x", 123);
pair<const string, int> p2("y", 321);
p1 = p2;


Says something about a remote assignment operator. I don't understand what's wrong... The most interesting thing is that if the strings are not constant, then everything works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Zhilin, 2020-05-21
@Xtone

Your assignment does p1.first = p2.firstand p1.second = p2.second. But you prevented assigning to p1.firstby declaring it as const.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question