Re: base/derived name unhiding but with ctors

From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 03/29/04


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!" :-)



Relevant Pages

  • Re: Use of new and delete in C++
    ... the array is not known outside of the constructor. ... > Take the pointer out of the constructor. ... Is there a way to make the destructor aware of the ... >> be overwritten, so that when the window is finished, it can rewrite the ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Question about arrays in objects
    ... >>I want to create a 2d array as an object member. ... > handled in the constructor, you just can't use a plain old array. ... > that is where using a pointer would come in. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Strange EAccessViolation which I cannot figure out...
    ... where in your code you are freeing and setting it to NIL to then later ... The proper way is to always create it in the constructor or, ... type cast around this returned value as a pointer to a pchar string. ...
    (comp.lang.pascal.delphi.misc)
  • Re: C++ 101 dumb question
    ... Yep I do comprehend the difference between a pointer and the data it ... If you have a CMyClass a; ... What does the signature of a copy constructor look like? ... Its action is to copy the data members of the class, ...
    (microsoft.public.vc.language)
  • Re: Address of temporary objects
    ... >> constructor gets called and inside it i see that the address of the ... >> but when entering to foo() i see that the address of the temporary ... > real compiler may emit opcodes to do anything, ... pointer to another field and in the copy constructor i'm initializing ...
    (comp.lang.cpp)