Board index » cppbuilder » Thanks to everybody

Thanks to everybody


2006-03-20 10:36:00 PM
cppbuilder17
Hi,
Finally i would say that the Delphi behaviour seems to me more logical. We
expect that the last virtual method is called in the last children even if
this virtual method is called in the constructor.
Imagine in a child you want to perform an operation in the constructor who
imply a virtual method of the base class. Then you are in the ...
Many thanks to everybody,
Regards,
Lionel
"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >a écrit dans le message de
Quote
At 01:32:27, 20.03.2006, Remy Lebeau (TeamB) wrote:

>
>"Lionel Reynaud" < XXXX@XXXXX.COM >wrote in message
>news: XXXX@XXXXX.COM ...
>
>>Many thanks for your c++ courses. Effectively my understanding of
>>how C++ works is not optimal !! That's because i work generaly
>>with Delphi.
>
>The creation order of objects in Delphi is the opposite than it is in
>C++.

Just like what Liz said, that is wrong. It is not opposite, it just not
always the same. But generally, it is the same as in C++.
--
Rudy Velthuis [TeamB] rvelthuis.de/

"Giving birth is like taking your lower lip and forcing it over
your head." - Carol Burnett.
 
 

Re:Thanks to everybody

"Lionel Reynaud" < XXXX@XXXXX.COM >writes:
Quote
Hi,

Finally i would say that the Delphi behaviour seems to me more
logical. We expect that the last virtual method is called in the
last children even if this virtual method is called in the
constructor. Imagine in a child you want to perform an operation in
the constructor who imply a virtual method of the base class. Then
you are in the ...
The C++ "way" makes perfect sense when you think about how the object
model works. If you look at it through the lens of a Delphi
programmer it look strange because it's not aligned with what is
familiar.
The key point to remember in C++ is that object lifetimes are defined
like this: they begin when their constructor FINISHES, and then end
the moment the destructor BEGINS.
Thus, if you could call a virtual function in a base class that
invoked code that ran in the context of the derived part, you are
essentially calling a function on an object that doesn't exist, and
that results in undefined behavior.
It's not generally good coding practice to write functions that
constantly have to check "have I been created? Is my pointer valid?
Have I been destroyed?" And so on. When you work with C++ in such a
way as to maximize the BENEFITS of its design, you can avoid having to
write such runtime checks. Trying to write in SPITE of its design
means you're really just coding Delphi using C++'s syntax, which
probably is the worst of both worlds.
--
Chris (TeamB);