Quote:
Originally Posted by arun.viswanath
Can any one explain how the statement '2' in the following statements is a legal one.
int & ref = 3; // Illegal statement - Compiler error.
const int& ref=3 ; // Compile and executes properly.
Thanks in Advance,
Arun
Arun,
value of '3' is a constant hence it can only be assigned to a const reference. below example will help you to understand better.
likewise say if you have:
int a=3;
int &b = a; //this is perfectly legal
const int &c = a; //this is legal
while if you had
const int a=3;
int &b = a; //illegal because : cannot convert from 'const int' to 'int &'
const int &c = a; //this is legal
rishi