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. Advertisements

  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. Advertisements

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. Alex Vinokur
    Replies:
    4
    Views:
    3,344
    Peter Koch Larsen
    Nov 26, 2004
  2. Mark Stijnman
    Replies:
    2
    Views:
    735
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Apr 22, 2005
  3. Tim Clacy
    Replies:
    15
    Views:
    3,017
    Kanenas
    May 30, 2005
  4. John Goche
    Replies:
    2
    Views:
    485
    Frederick Gotham
    Sep 4, 2006
  5. Replies:
    4
    Views:
    672
    Alf P. Steinbach
    May 23, 2007
  6. Replies:
    1
    Views:
    539
    Victor Bazarov
    May 23, 2007
  7. Javier
    Replies:
    2
    Views:
    892
    James Kanze
    Sep 4, 2007
  8. MWimmer
    Replies:
    7
    Views:
    517
    James Kanze
    Oct 23, 2007
Loading...