Thread View: comp.std.c++
2 messages
2 total messages
Started by Thomas Ngo
Mon, 30 Jul 1990 14:07
How does a reference differ from a const *const?
Author: Thomas Ngo
Date: Mon, 30 Jul 1990 14:07
Date: Mon, 30 Jul 1990 14:07
5 lines
731 bytes
731 bytes
How does a reference differ from a const pointer to a const
object (besides the obvious need to dereference the latter)?
I hope this question is in the spirit of this newsgroup.
Re: How does a reference differ from a const *const?
Author: Ron Guilmette
Date: Tue, 31 Jul 1990 21:37
Date: Tue, 31 Jul 1990 21:37
53 lines
2261 bytes
2261 bytes
In article <3679@husc6.harvard.edu> ngo@tammy.harvard.EDU (Thomas Ngo) writes: > > How does a reference differ from a const pointer to a const > object (besides the obvious need to dereference the latter)? > > I hope this question is in the spirit of this newsgroup. As you note, the first difference is that references are implicitly dereferenced (in almost all contexts - including sizeof). Also, since you cannot change the value of a reference (once it has been initialized) it seems that references are (in this respect) very much like const pointers. Note however that the referent object of a reference could be either const or non-const, just as the referent of a pointer variable could be. Some differences that come to mind are: 1) Pointers to pointers are allowed. Pointers to references are not. 2) References to pointers are allowed. References to references are not. 3) Arrays of pointers are allowed. Arrays of references are not. (At least the last time I asked Bjarne, he said that he put that in the language but then decided that it was a mistake and that it ought to be taken out again.) 4) Given the declarations: extern int array[], func(); and the function call: foobar (array, func); the following possible declarations for foobar() will "match": extern void foobar (int* const arg1, int (* const arg2)()); it is not at all clear however (to me anyway) whether or not the following declaration would also "match" the call above: extern void foobar (int& arg1, int (& arg2)()); I'm sure that there are more, but I have forgotten them. -- // Ron Guilmette // C++ Entomologist // Internet: rfg@ncd.com uucp: ...uunet!lupine!rfg // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads