|
Boost Users : |
From: Aljaz (aljaz.fajmut_at_[hidden])
Date: 2007-02-16 03:20:33
>> Do I have to register_type this way? Can I use BOOST_EXPORT ..
>> instead?
>
> Yes
I tried doing BOOST_CLASS_EXPORT(B), but program crashed when I wanted to
deserialize data..
>>When I want to deserialize data, the derived class will be
>> unknown, so I have to deserialize data with base class shared
>> pointer..
>
>> This will then contain information - type of derived class, and then
>> I will cast it to derived class..
>
> You may not have to do this. And you may not want to. The typical
> use case for using an abstract base class is to have all the functions
> in the derived class declared private and be called only through the
> the virtual function table in the abstract base class. The separates
> the interface defined in the abstract base class defined from the specific
> implementation in the derived class.
>
>> How could I do this?
>
> a) You can embed a function in the base class like who_am_i() which
> returns an indictator of what kind of class it "really" is.
> b) you can use a function from the extended_type_info family of
> the serialization library to do something similar
>
> Neither of these are recommend as far as I'm concerned. The best
> is to make all the functions you want to call virtual and call them
> through
> the base class. This topic is addressed in Scott Meyers "Effective C++"
>
> Another effect is that you can add more derived classes without even
> recompiling the code you're already using. There is a demo in the
> serialization library which illustrates this.
Why I want to ID derived class through base class? Because derived class
will contain a lot of data, that wont be in base class.
If I had only functions in derived class, I would make them virtual and call
from base class..
I already made function get_type() that returns type of derived class.. But
I still have no idea if I have smart pointer to base class, how do I get
smart pointer do derived class from it?
Is there any example using extended_type_info family to do something
similar?
Thank you!
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net