Thiago R. Adams website

Home Code-Blog Projects Twitter Blog Links / Books About

Websites

Disabling constructors that you are not using

If you are not implementing the default constructor, copy constructor or the assignment operator, it is a good idea to declare them but do not implement then. Doing this, you prevent that they are called automatically leaving uninitialized variables.

class X {

  X(); // not used
  X(const X &); // not used

  Object * m_p;

public:

  X(Object * p) : m_p(p) {}
};

Want to see more? Go to the CodeBlog section.

About the author: I am Thiago Adams. I work as a professional C++ software engineer. I have created this website to share ideas and source code with other people with similar interests.
I would like to hear from you comments, critics, questions and suggestions about this topic or any other part of this website. Email: thiago.adams at gmail dot com