Default constructors - I don't want em!

So, what do I do if I want an object to not have an available default constructor? Many of the objects I want to make should require that pointers to other objects be passed into it during creation. What is the best way of ensuring this?
Make it private.
Yes, declare it as private. you don't have to provide a body either, just the declaration will stop the compiler doing one for you.
When you provide your own constructor the default constructor is no longer created. This seems to be what you want. Making a constructor protected or private makes sense only in a few cases, e.g. when creating signletons.

Of course, when you provide your own "normal" constructor(s), the default copy-constructor is still generated. You have to overwrite this one seperately, especially when dealing with pointers (depending on whether they represent associations or aggregations/compositions) one should not forget to do so.
Last edited on
Topic archived. No new replies allowed.