Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C++, we can't declare a reference without initialization. Why? [closed]

In C++, we can't declare a reference without initialization. What is the actual reason for this.Although we are aware about the uses of references in operator overloading and other concepts.

like image 812
Rajesh Sethi Avatar asked May 07 '26 20:05

Rajesh Sethi


1 Answers

C++ references (in the ordinary C++ meaning of that word) can't be reassigned. So if a reference isn't initialized it can't be made to refer to anything. And the language does not support null-references, hence, an uninitialized reference, if such were permitted, would always be in error.

like image 85
Cheers and hth. - Alf Avatar answered May 10 '26 10:05

Cheers and hth. - Alf