469,322 Members | 1,573 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,322 developers. It's quick & easy.

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

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.

May 22 '07 #1
1 1842
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>>
};
May 23 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Victor Irzak | last post: by
10 posts views Thread by placid | last post: by
12 posts views Thread by Michael Maes | last post: by
2 posts views Thread by Tom Smith | last post: by
6 posts views Thread by AzizMandar | last post: by
4 posts views Thread by developereo | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.