Re: base/derived name unhiding but with ctors
From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 03/29/04
- Next message: Bill Seurer: "Re: Why do you need a Ph.D. to do quant?"
- Previous message: Karl Heinz Buchegger: "Re: macro for enum to string?"
- In reply to: Alf P. Steinbach: "Re: base/derived name unhiding but with ctors"
- Next in thread: Alf P. Steinbach: "Re: base/derived name unhiding but with ctors"
- Reply: Alf P. Steinbach: "Re: base/derived name unhiding but with ctors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Mar 2004 17:30:35 +0200
Alf P. Steinbach wrote:
> * Rolf Magnus <ramagnus@t-online.de> schriebt:
>>
>> How do you call something that doesn't have a name?
>
> That depends on the something. If e.g. it is a pointer to a function
> then you can use ordinary function call syntax with the pointer taking
> the place of a function name.
That function still has a name. But you're right in that this name isn't
used if the function is called through a pointer. However, you once
used the name to assign to the pointer. Anyway, you cannot have a
pointer to a constructor, because you cannot call a constructor,
neither through its name (which it doesn't actually have) nor through a
pointer to it (which you could only get by using the name, since code
cannot be dynamically allocated in C++). It also wouldn't make sense to
only call a raw constructor, because more is needed to create an
object, and that can't be explicitly done by the programmer.
> For constructors you can use that syntax with the name of the class
> taking the place of the function name; formally it then ends up as a
> functional notation type conversion, but very few programmers care or
> know that all of their constructor calls are formally conversions.
But most of them know (hopefully) that all of their "constructor calls"
actually do create complete objects and not just call their constructor
code.
> Since you have demonstrated non-grokking of fundamentals in this
> respect
I understand well. I just don't use your confusing terminology for
describing it.
> before I hasten to repeat from earlier in the thread, that
> that syntax alone does not call a constructor on pre-existing storage.
>
> To do the latter use placement new, but preferably, don't.
Even placement new won't just call a constructor. It will create a full
object. It just happens to create that object in-place instead of first
reserving new storage for it.
> The standard often, by necessity, talks about constructor calls, so
> even you should be able to see that your statement is false.
Well, constructors must be called somewhere. Just not by the programmer.
It's called by the implementation whenever an object is to be created.
The programmer just says "make me an object", and the implementation
does whatever is needed to do that (part of which is of course a call
to the constructor).
> The standard however seldom refers to source code constructor calls as
> constructor calls, which is wise given e.g. your severe confusion.
>
> But it does in at least one place: "A default constructor for a class
> X is a constructor of class X that can be called [source code call]
> without an argument".
Hmm, that's actually strange, because OTOH, it speaks about "pseudo
destructor calls", because a destructor can't be called, just like a
constructor. Instead you use something that looks like a "destructor
call" if you want to destroy an object in-place.
>> So you say that those "90+ percent of C++ programmers" are all wrong?
>
> Yep.
Sounds to me like the person who hears the traffic news in his car,
where they say that someone is driving on the wrong side of the
highway, and he says "One? Hundreds!" :-)
- Next message: Bill Seurer: "Re: Why do you need a Ph.D. to do quant?"
- Previous message: Karl Heinz Buchegger: "Re: macro for enum to string?"
- In reply to: Alf P. Steinbach: "Re: base/derived name unhiding but with ctors"
- Next in thread: Alf P. Steinbach: "Re: base/derived name unhiding but with ctors"
- Reply: Alf P. Steinbach: "Re: base/derived name unhiding but with ctors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|