What does const
signify in a function declaration like int const& foo()
? Does it mean the function will not modify any variables, or that it returns the address of a variable which is constant?
Asked
Active
Viewed 142 times
-3

Remy Lebeau
- 555,201
- 31
- 458
- 770

blarredflunky
- 43
- 1
- 4
-
2Possible duplicate of [When should I return by T const&?](https://stackoverflow.com/questions/16964107/when-should-i-return-by-t-const) – Mar 13 '18 at 02:26
-
It's the same thing as const int & foo(); – Zebrafish Mar 13 '18 at 03:00
1 Answers
1
It's the latter case in your question. int const& foo()
means that the function returns a reference to a const int
. So, you can't do something like foo() = 42
, for instance.

Remy Lebeau
- 555,201
- 31
- 458
- 770

Gabriel
- 829
- 5
- 12