How to setup the c++ rule of three in a virtual base class

Posted by Minion91 on Programmers See other posts from Programmers or by Minion91
Published on 2012-10-01T08:59:19Z Indexed on 2012/10/01 9:49 UTC
Read the original article Hit count: 296

Filed under:
|
|
|

I am trying to create a pure virtual base class (or simulated pure virtual)

my goal:

  1. User can't create instances of BaseClass.
  2. Derived classes have to implement default constructor, copy constructor, copy assignment operator and destructor.

My attempt:

class Base
{
public:
    virtual ~Base() {};
    /* some pure virtual functions */
private:
    Base() = default;
    Base(const Base& base) = default;
    Base& operator=(const Base& base) = default;
}

This gives some errors complaining that (for one) the copy constructor is private. But i don't want this mimicked constructor to be called.
Can anyone give me the correct construction to do this if this is at all possible?

© Programmers or respective owner

Related posts about c++

Related posts about c++11