Say I have a base class:
class baseClass
{
public:
baseClass() { };
};
And a derived class:
class derClass : public baseClass
{
public:
derClass() { };
};
When I create an instance of derClass
the constructor of baseClass
is called. How can I prevent this?
Make an additional empty constructor.
struct noprapere_tag {};
class baseClass
{
public:
baseClass() : x (5), y(6) { };
baseClass(noprapere_tag) { }; // nothing to do
protected:
int x;
int y;
};
class derClass : public baseClass
{
public:
derClass() : baseClass (noprapere_tag) { };
};