|
Boost : |
From: Dave Harris (brangdon_at_[hidden])
Date: 2005-10-27 13:19:01
In-Reply-To: <1130423747.22962.246152955_at_[hidden]>
atompkins_at_[hidden] (Andy Tompkins) wrote (abridged):
> I have also realized that (for my purposes) I don't require the
> ability to delete people from a pointer to its base class
> [code skipped]
You might consider having wrap_vector inherit privately from std::vector
and adding using-declarations rather than forwarding functions. I don't
think using composition gains much, given that you are going to inherit
from wrap_vector anyway. Using-declarations would be less code, possibly a
lower abstraction penalty and would avoid problems with tracking exactly
the std vector declarations.
> // overload wrap_vector member functions for different behavior
That's risky, because there is an implicit conversion from people to
wrap_vector<person> and your overloads won't affect the wrap_vector
versions.
What I think you really want to do is prevent the derived to base
conversion. It's a shame this doesn't work:
#include <vector>
struct Container : public std::vector<int> {
typedef std::vector<int> base;
private:
operator base &();
operator const base &() const;
};
void test() {
Container *p1 = new Container;
Container::base &p2 = *p1; // Shame this compiles.
}
Maybe it is worth floating in comp.std.c++.
-- Dave Harris, Nottingham, UK.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk