Boost logo

Boost :

Subject: Re: [boost] [intrusive] rtti_base class proposition
From: Ireneusz Szpilewski (irek_at_[hidden])
Date: 2009-10-21 15:56:40


Matus Chochlik wrote:
> On Wed, Oct 21, 2009 at 3:09 PM, Ireneusz Szpilewski
> <irek_at_[hidden]> wrote:
>
>> Stewart, Robert wrote:
>>
>>> Ireneusz Szpilewski wrote:
>>>
>>>
>>>> [...]
>>>> I don't care what you call it. There is no good reason to do this in
>>>> C++.
>>>>
>>>> [snipped examples of using containers of heterogeneous types.]
>>>>
>>>> I'm well aware of uses of this approach and they are usually misguided.
>>>> A common base class is not terribly helpful. One specific to a particular
>>>> use case is far more useful. Using your approach encourages programming
>>>> with dynamic_cast. There are times when it is needed, but its use should be
>>>> limited and not encouraged generally.
>>>>
>>>>
>
> I agree that defining and using a common base class for all other classes
> in a project is in 99% of cases a very bad idea. There is a book called
> "C++ Gotchas: Avoiding Common Problems in Coding and Design"
> and the use of such "cosmic hierarchies" is a gotcha #97 ;-)
>
>
Don't look at class hierarchy, look at object. It would be composed
of many
other subobjects (by means of multiple inheritance), just as a human body is
composed of different organs. What's wrong with fact that all men have
penises?
(I will make "rtti_base" tattoo on mine) Of course man should have one
penis,
so every class should inherit rtti_base virtually. (By the way, C++
virtual inheritance
implementation is broken) I insist on that deriving from rtti_base is
voluntary and
controlled by a particular class hierarchy designer. In our analogy -
every man can
have his penis cut off if he (or his wife) doesn't need it. What can you
do with penises?
We all know what. ;-) And what can we do with rtti_base? If we have
pointer to it,
we can query the pointed object using RTTI.

Ireneusz Szpilewski


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk