S
S
sddvxd2018-03-31 20:22:00
C++ / C#
sddvxd, 2018-03-31 20:22:00

Why use const qualifier in return value?

Good evening. Everything is clear here: we promise the compiler not to change the object, we return the same that we get (a reference to the object), we forbid changing the structure of the incoming object . Only the purpose of the following prototype is not clear: Namely, the first qualifier. What for in return to specify the qualifier const?
String& String::test(const String&)const;
const String& String::test(const String&)const;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-03-31
@sddvxd

const String& String::test(const String&)const;
What for in return to specify the qualifier const?

In the same place, the link is returned so that the line by reference is not changed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question