Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Derived::Derived(const Base&) and Derived& operator=(const Base&) (http://www.velocityreviews.com/forums/t508446-derived-derived-const-base-and-and-derived-and-operator-const-base-and.html)

developereo@hotmail.com 05-22-2007 06:55 PM

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.


myork 05-23-2007 12:07 AM

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

> 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>>
};




All times are GMT. The time now is 01:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.