Kai-Uwe Bux
10/25/2008 7:41:00 PM
Marcel Müller wrote:
> Hi,
>
> is there a way to avoid the automatic copy constructor generation. I do
> not want the object to be non-copyable. I simply do not want that
> copying is done by the default copy constructor. But there is a
> constructor that accepts the base class. This one should be used for
> copying.
>
> In fact i have a set of classes with a common abstract base. The
> implementations do not have own data members. They only implement
> different functionality. But is makes sense to do assignments and copy
> construction between these set of types. This effectively changes the
> functionality depending on the current type.
[snip]
What about implementing a copy-constructor for the Base and then have
class Derived_1 : public Base {
Derived_1 ( Base const & other )
: Base ( other )
{}
Derived_1 ( Derived_1 const & other )
: Base ( other )
{}
};
and similarly for Derived_2, ... ?
I think, if the copy-constructor for Base is implemented properly, the
compiler-generated copy-constructor for the derived classes would do the
same thing as the above, so you could even ditch that. Now, _that_ looks
very much like the code, I snipped. I clearly do not understand your
problem. Maybe, you need to post more details, because I lack the
imagination for:
> Furthermore the auto
> generated copy constructor is unusable. It has undefined behavior
> because of some special internal storage dependencies. It also has to do
> with multiple inheritance, so I could not move the code to a member
> function either.
If that is true, I do not see how the constructors _from_ the base can
possibly work correctly if they are just:
> Container1(const ContainerBase& r)
> : ContainerBase(r)
> {}
Best
Kai-Uwe Bux