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: 301
I am trying to create a pure virtual base class (or simulated pure virtual)
my goal:
- User can't create instances of BaseClass.
- 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