I am a little confused by this:
I thought that if the pointer points to some object, the purpose of dereferencing some reference variable was a simple alias.
Example:
Object * p = &o;
Object & r = *p;
I knew that there were some illegal cases, for example:
Object * p = NULL;
Object & r = *p;
Now, what about the code below?
const char * p = "some string";
const char & r = *p;
or
const char & r = *"some string";
I was told that this particular case concerns temporary objects, and therefore I could not get the address r and be sure that it would point to a memory array containing my starting line.
What does the C ++ standard mean in this case? Whether this is another illegal case, such as a NULL position, or behavior is allowed.
In other words, is it legal or illegal (undefined behavior?) To write something like?
char buffer[100];
strcpy(buffer, &r);
kriss source
share