Derived::Derived(const Base&) and Derived& operator=(const Base&)

D

developereo

Hi folks,

Can somebodyshed some light on this problem?

class Interface {
protected:
Interface() { ...}
virtual ~Interface() { ... }

public:
virtual method() = 0;
}

class Impl1: public Interface {
public:
Impl() { ... }
Impl(const Interface&); // problem 1
virtual ~Impl() { ... }
Impl& operator=(const Interface&); // problem 2
virtual method() { ... }
}

The problem is that the compiler (VC 2005) insists on generating
Impl1(const Impl1&) // copy constructor
and
Impl& operator=(const Impl1&) // default assignment operator

The problem is I do not want these methods. I want any Impl to be
able to construct/assign itself from any (other) Impl satisfying the
Interface. That's the whole point of having an Interface. I
shouldn't need these methods. The compiler should be able to use my
methods since every Impl is also an Interface, no?

Thanks,
J.
 
M

myork

The problem is that the compiler (VC 2005) insists on generating
Impl1(const Impl1&) // copy constructor
and
Impl& operator=(const Impl1&) // default assignment operator

The problem is I do not want these methods.

Declare them private and do not provide an implementation:

class Impl1: public Interface
{
private:
Impll(const Impll& copy); // Not implemented.
Impll& operator(const Impll& copy); // Not implemented.

<<STUFF>>
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top