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

Discussion in 'C++' started by developereo@hotmail.com, May 22, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. myork Guest


    > 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>>
    };
     
    myork, May 23, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Clacy
    Replies:
    15
    Views:
    2,751
    Kanenas
    May 30, 2005
  2. Replies:
    4
    Views:
    436
    Alf P. Steinbach
    May 23, 2007
  3. Replies:
    1
    Views:
    405
    Victor Bazarov
    May 23, 2007
  4. Javier
    Replies:
    2
    Views:
    618
    James Kanze
    Sep 4, 2007
  5. MWimmer
    Replies:
    7
    Views:
    393
    James Kanze
    Oct 23, 2007
Loading...

Share This Page