Private constructor

Joined
Jun 3, 2010
Messages
1
Reaction score
0
Maybe I am misunderstanding. I hope you folks can set me straight.

I understand that I can declare a private constructor in a class. I do this at times in order to simply provide the member functions for the class. But now I am trying to declare a descendant of this class with the private constructor and the compiler is complaining.

class foo {
private:
foo(){}
~foo(){}
};

class foo2: public foo {
public:
foo2(){}
~foo2(){}
};

I would like to prevent someone from creating a foo2 object from being able to call the constructor/destructor directly, but the compiler complains that foo(){} is private.

Is there a different way to prevent access to the constructor/destructor from foo2, or am I just practicing bad design here?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top