Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ const semantics for a reference

If there is something like below in code:

func(const base& obj)

what does the const semantics mean? What is constant here ? Is obj a const reference to a non-const object or a non-const reference to a const object?

like image 602
nitin_cherian Avatar asked Dec 06 '22 17:12

nitin_cherian


1 Answers

There is no such thing as a "non-const" reference, that is, a reference is always bound to the same object and there is no way to change that. "const type&" means reference to const type.

like image 188
Tavian Barnes Avatar answered Jan 01 '23 14:01

Tavian Barnes