Newsgroups: comp.lang.c++
From: blargg....@gishpuppy.com (blargg)
Date: Sun, 22 Feb 2009 15:10:14 -0600
Local: Sun, Feb 22 2009 9:10 pm
Subject: Re: Automatically create a clone() function for derived classes
In article <l3znl.97$zj6...@read4.inet.fi>, Juha Nieminen
[...] > 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 > Isn't there any way of automating this process? Odd-ball approach that comes to mind, if compile-time checking is class Clonable { // OK to remove this class Base : protected virtual Clonable { class Derived : public Base { class Error : public Derived { class Error2 : public Derived { You could probably use a similar approach, with Clonable generating the 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.
| ||||||||||||||