Re: Is it possible to assign a default value...great, but how?
From: John Carson (donaldquixote_at_datafast.net.au)
Date: 04/18/04
- Next message: Rob Bolton: "Re: Can't get something basic to work (WMI)"
- Previous message: Steven: "Close Remote Files using WMI?"
- In reply to: David F: "Re: Is it possible to assign a default value...great, but how?"
- Next in thread: Simon Trew: "Re: Is it possible to assign a default value...great, but how?"
- Reply: Simon Trew: "Re: Is it possible to assign a default value...great, but how?"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 18 Apr 2004 19:03:11 +1000
"David F" <David-White@earthlink.net> wrote in message
news:55qgc.18443$A_4.15300@newsread1.news.pas.earthlink.net
> My understanding from your answer to the question "Is it possible..."
> in one word is simply... NO.
Correct.
> As far as the type X is concerned, I would hope that it is clear that
> it does NOT matter what type is it, whether int or class, for example.
> The key point and the clarification I made following immediately my
> original posting, is as follows:
> "I meant of course a default value that addresses no real object,
> much as NULL does it with pointers".
I did not notice your clarification owing to your decision to put it in the
subject line rather than the body of your post. You might be interested to
know that your changes of subject have caused this thread to be split into 3
separate threads on Google Groups. I mention this not because I actually
read your posts in Google Groups but as one reason why people don't normally
change subject lines and hence one reason why readers of posts don't look to
subject line changes as sources of information.
> While for pointers, again, regardless of the type of X I can write:
> "void f(X* p = NULL) { }", where X doesn't have to exist as an actual
> object,
What you mean is that NULL is not an address of an X object.
> and the meaning is that p points to nothing, Consequently, I
> can call f like this: f().
You can call f like that without the availability of a NULL.
> I was looking for a similar / parallel answer for a reference: "void
> f(X& r = NOTHING) { }", where X doesn't exists as an actual object
What you mean is that NOTHING is not an X object.
> and r references or is the address of nothing. The term NOTHING is
> of course my invention just to demonstrate my point. So again, I
> could call f() in the case of a reference argument too.
You can call f() without there being a NOTHING in the language.
> Logically speaking, there is no reason not to have it, much the same
> way we have it fot pointers.
>
The other side of making NOTHING available for those who want it is that
everybody would then have to test that r!= NOTHING before performing
operations on r. The existing arrangement offers something to everyone;
those who need to be able to use NULL can use pointers, those who don't want
to bother testing for whether they are dealing with something non-NULL can
use references. Another way around the problem is to use function
overloading, i.e., define a separate
void f()
{
// stuff
}
in addition to
void f(X& r)
{
// stuff
}
-- John Carson 1. To reply to email address, remove donald 2. Don't reply to email address (post here instead)
- Next message: Rob Bolton: "Re: Can't get something basic to work (WMI)"
- Previous message: Steven: "Close Remote Files using WMI?"
- In reply to: David F: "Re: Is it possible to assign a default value...great, but how?"
- Next in thread: Simon Trew: "Re: Is it possible to assign a default value...great, but how?"
- Reply: Simon Trew: "Re: Is it possible to assign a default value...great, but how?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|