D
doublemaster007
1. const string & fun()
{
return "Hello";
}
Above code compiles..
but not this...
2. string & fun()
{
return "Hello";
}
It seems..we canot have non-const ref to tempo's.. But i would like to
know what is it that we have achieved making just reffrence to const??
Isnt that tooo bug or catastrophic?? What is the motive behing
specifiaction allowing const ref to tempo's??
in the case of example (1) compiler says that "invalid inialization of
non-const string& to "const char *"..
if "Hello" is the const char * type...then
How can we assign char * str = "Hello"; and even we can do str[2]='c';
compiler wont report any error...
Pls solve my mystry..
{
return "Hello";
}
Above code compiles..
but not this...
2. string & fun()
{
return "Hello";
}
It seems..we canot have non-const ref to tempo's.. But i would like to
know what is it that we have achieved making just reffrence to const??
Isnt that tooo bug or catastrophic?? What is the motive behing
specifiaction allowing const ref to tempo's??
in the case of example (1) compiler says that "invalid inialization of
non-const string& to "const char *"..
if "Hello" is the const char * type...then
How can we assign char * str = "Hello"; and even we can do str[2]='c';
compiler wont report any error...
Pls solve my mystry..