Newsgroups: comp.lang.c++
From: Victor Bazarov <v.Abaza...@comAcast.net>
Date: Fri, 20 Feb 2009 10:09:50 -0500
Local: Fri, Feb 20 2009 3:09 pm
Subject: Re: Automatically create a clone() function for derived classes
Sana wrote: Then the problem would be with a derived class of a derived class (a > On Feb 20, 9:25 am, Juha Nieminen <nos...@thanks.invalid> wrote: >> class Base >> { >> public: >> virtual Base* clone() const { return new Base(*this); } >> // other stuff here >> }; >> The problem is that this clone() function must be replicated in all >> class Derived: public Base >> }; >> It's not only tedious to have to write this line in each of the > Make the Base::clone() method pure and don't provide a body. this way, "grandchild" of Base). Once the derived has implemented the clone function, any of its own derived classes won't be forced to do that. And that's actually reflected in the original inquiry since Base::clone In certain circles, a macro is used class Derived : public Base { which expands to declare the 'clone' member (with some possible V You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||