|
Boost : |
From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-12-10 11:17:38
"Johan Nilsson" <johan.nilsson_at_[hidden]> wrote in message
news:at52vi$si6$1_at_main.gmane.org...
[snip]
> I'd like to be able to store references to objects of arbitrary types in a
> homogenous collection, not requiring them to be derived from a common base
> class. For COM users, that would be something like an "IUnknown in the
> context of standard C++". I suspect that boost::any might be something
> similar to what I need, but I just got that idea using void pointers.
>
What's the point of that? I mean, with no interface to the types, you can't
do anything with these objects you're storing, not even delete them.
You could also do:
struct IHolder {
virtual ~IHolder () {}
};
template <typename Object>
class holder : public IHolder{
public:
holder (Object* const object);
~holder ();
};
It's always better to try and look for a real (type safe) solution than
playing around with type casting. It still depends on what you want to _do_
with theses objects behind this common, empty interface. I suspect problems
with your design if you have been led down this path.
[snip]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk