Boost logo

Boost :

Subject: Re: [boost] [intrusive] rtti_base class proposition
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-10-20 14:14:58

Ireneusz Szpilewski wrote:
> Stewart, Robert wrote:Stewart, Robert wrote:
> > Ireneusz Szpilewski wrote:
> >
> >> Every class deriving from rtti_base can be queried
> >> by means of RTTI, in particular rtti_base class
> >> and dynamic_cast can be used in similar way
> >> as IUnknown and QueryInterface() in
> >> COM Object Model
> >>
> > Why is a common, standardized or de facto standard name
> > needed? The
> > usual case is to create a base class for each context in
> > which a common base is desired.
> >
> Because that could be a C++ standard common class as Object in C# or
> IUnknown in COM.
> Let's call it object_t. ;-)
> Just not forced by language rules, but used at will if needed.
> Anyone could attach to it and have generic pointer to objects.

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.

In your cats and girls use case, the proper thing to apply is the Visitor Pattern. That permits you to do double-dispatch to determine the correct behavior when a visitor interacts with the objects in a room. Only when the visitor's type is combined with that of an object is the correct interaction known. Hard coding that into a function is a maintenance nightmare and should be avoided.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at