Boost logo

Boost :

Subject: Re: [boost] [intrusive] rtti_base class proposition
From: Ireneusz Szpilewski (irek_at_[hidden])
Date: 2009-10-20 13:47:38


Stewart, Robert wrote:Stewart, Robert wrote:
> Ireneusz Szpilewski wrote:
>
>> class rtti_base
>> {
>> virtual void _dummy() {}
>> };
>>
>
> Once you have virtual functions, you need a virtual destructor.
Hence the base class should define a virtual destructor and then there's
no need for _dummy().
>
>
Great idea! :-D
>> 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
>>
> [snip]
>
>> The main purpose of this class is
>> to set some standard name for that
>> pointer type.
>>
>
> 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.

As in my example above, I have a room where are cats and girls.
I want to give milk to cats and kiss girls.

There are two classes:

class Cat
{
  public:
   void GiveMilk();
};

class Girl
{
  public:
  void Kiss();
};

they have really nothing in common, but objects of both classes are in
my room.
So I add to them something by which I can hold them all via pointers,
and, in addition, query about their types.

Let's suppose you have the same problem with different (or not) classes
and have used also rtti_base to hold them all.
Then we both win! You can insert your objects into my container,
and if by accidence they derive from Cat or/and Girl, they will be
pleased in my room. If I put my objects into your collection
std::stack<rtti_base*> for example, they can also be pleased if
you GiveMilk() to Cats and Kiss() Girls. :-)

(By the way std::shared_ptr<rti_base*> would give us
C++ equivalent of IUnknown interface with metods:
QueryInterface();
AddRef();
Release();
)

Ireneusz Szpilewski


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