Re: Deriving from concrete types
Oleksandr Yefremov wrote:
template<class T>
class extended_vector : public vector<T>
{
public:
// our super duper function
void extendet_function();
};
template<class T>
class extended_vector2 : private vector<T>
{
public:
// multiple using declarations of vector interface
// using ...
// using ...
// our super duper function
void extendet_function();
// to be able use extended_vecotr2 where vector expected
operator vector<T>&() {return *this;}
operator const vector<T>&() const {return *this;}
};
In this example extended_vector and extended_vector2 will work in the
same way. Final user can delete both of them using base class pointer.
No. When the user creates an object of the first, deleting via a pointer to
the baseclass yields UB. With the second, the case is slightly different,
because they first need to invoke the user-defined conversion operator. If
it was a real memberfunction like get_base() I would say that this
implicitly tells the user that they are not supposed to delete it (like you
would never do when you got a reference from a functioncall) but even these
user-defined operators require rather malicious code in order to extract a
pointer to baseclass and then to delete it.
Anyhow, I don't think that direct access to the baseclass is intended,
because all functions that should be accessible (and the destructor is
simply not one of them) are made available via using declarations.
ignore OOD if it limit your code.
Yes, OOD/OOP is only a tool. If it doesn't fit your problem, don't use it.
Uli
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]