This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: unneeded stuff when call


At 10.05 04/07/2003 +0530, Anirudha wrote:
i knew from what i read that references in C++ are constant pointers which
are automatically dereferenced..
And once a reference is initialized to an object, it cannot be changed to
refer to another object.
so something like this shud not work..
int main()
{
     int p=15;
     int m=10;
     int &s=p;
     s=m;
   }
on the last line it shud give compile time error.
But it's compiling as well as running fine in GCC..

You cannot change what the reference "automatic pointer" points to (ie., p, in your example), but you can change the value of that variable.
Your example is equivalent to:


int main (void)
{
    int p=15;
    int m=10;
    int * const s=&p;
    *s=m;
}

.fw.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]