Making inheritance less tedious
janderson
askme at me.com
Wed Feb 28 22:06:47 PST 2007
Kevin Bealer wrote:
> I've often thought that in C++ I could achieve neat results by copying the vector,
> string, and map classes and adding my own functionality, but there is the
> annoyance of duplicating the half dozen or so string constructors. The simplest
> c++ syntax I have found is this (not tested):
>
> class MyString : string {
> public:
> template<A> MyString(A x) : string(x) {}
> template<A,B> MyString(A x, B y) : string(x,y) {}
> template<A,B,C> MyString(A x, B y, C z) : string(x,y,z) {}
> };
[snip]
This is where I think well designed mixins really start showing their
power. The problem in C++ is that the base classes are not written in
the mixin design pattern, probably because its yet another level of C++
complexity to add. In D mixins are easy, so theres is really no excuse.
Having said that I don't think they solve this problem entirely.
=Joel
More information about the Digitalmars-d
mailing list