Re: Pointer of Reference ?
From: Michael Schlenger (Michi-Schlenger_at_web.de)
Date: 06/14/04
- Next message: KS: "Re: CFile class Bug?"
- Previous message: homecurr_at_yahoo.com: "Start a CDialog from a CToolbarCtrl"
- In reply to: Joseph M. Newcomer: "Re: Pointer of Reference ?"
- Next in thread: Joseph M. Newcomer: "Re: Pointer of Reference ?"
- Reply: Joseph M. Newcomer: "Re: Pointer of Reference ?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Jun 2004 18:11:32 GMT
On Fri, 11 Jun 2004 17:34:04 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:
>It also saves you from that ugly misfeature of C where you must use . for objects and ->
>for pointers (but if you get it wrong, the compiler complains. Of course it never occurred
>to the language designers that if the compiler can tell the difference, the programmer
>shouldn't need to!).
I see it exactly the other way around. A pointer is something
completely different from a reference, and you should make it damn
clear in your code what you mean. It is good that the compiler tells
you if you do something other that you mean - that is, "the compiler
is your friend", as I always say.
More general, it usually is NO GOOD IDEA to have the compiler make
assumptions about what you might have intended. Things like
void f( int );
f( "5" );
simply should not compile although there is an obvious semantic
interpretation of the two statements.
[snip]
> ASSERT(pDC != NULL);
> ASSERT(pBitmap != NULL);
is there any reason why you do not simply write
ASSERT( pDC );
Do you also write
if ( someBool == true )
?
BTW, in C++ the null pointer is noted as 0, NULL is not part of the
language, it is some library thing.
[snip]
>Some will argue that putting the & at the call site makes it obvious that the object can
>be modified, but I think this argument is specious.
This argument is completely wrong. To specify that a server does not
modify an object, the language provides the const specifier.
For some type T, the statements
void f( const T& );
void f( const T* );
both signal to the caller that the function cannot modify the object.
That has nothing to do with the pointer/reference thing. The good
thing of course is that the compiler can enforce this - again: the
compiler is your friend.
------------------------------------------------
Michael Schlenger
------------------------------------------------
- Next message: KS: "Re: CFile class Bug?"
- Previous message: homecurr_at_yahoo.com: "Start a CDialog from a CToolbarCtrl"
- In reply to: Joseph M. Newcomer: "Re: Pointer of Reference ?"
- Next in thread: Joseph M. Newcomer: "Re: Pointer of Reference ?"
- Reply: Joseph M. Newcomer: "Re: Pointer of Reference ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|