Skip to content

Checklist for (C++) class authors

January 11, 2007

I’ve been reading, “Ruminations on C++”, an interesting C++ book by Andrew Koenig and Barbara Moo. It tries to explain the “why” of C+ programming instead of just the “how”. It also gets you to think more about your programming.

I found this list of questions for designing classes useful.

  • Does your class need a constructor?
  • Are your data members private?
  • Does your class have a constructor without arguments?
  • Does every constructor initialize every data member?
  • Does the class need a destructor?
  • Does the class need a virtual destructor?
  • Does your class need a copy constructor?
  • Does your class need an assignment operator?
  • Does your assignment operator handle correctly assignment of an object to itself?
  • Does your class need to define the relational operators?
  • Did you remember to say delete[] when deleting an array?
  • Did you remember to say const in the argument types of your copy constructor and assignment operator?
  • When a function has reference parameters, should they be const references?
  • Did you remember to declare your member function const appropriately?
About these ads

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: