Initialize Not Assign

Somewhere in my travels on the web (and I think it was here on Wiki) I saw a reference to a pattern called something like InitializeNotAssign.

It concerned the use of the C++ constructor member initialisation list. e.g. given a class

  class Myclass
  {
  public:
int a,b;
Myclass();
  };
This
  Myclass::Myclass() : a(1), b(2) {}
is preferable to
  Myclass::Myclass() { a = 1; b = 2; }
Someone has asked why and I wanted to throw the pattern into the discussion. Anyone seen it?


OK, I found it again. It's specific to C++ so I won't quote it here. It was in the May 96 C++ Report, and article by JimCoplien called "After all we can't ignore efficiency".

For those interested the article is available at http://www.sigs.com/publications/docs/cppr/9605/cppr9605.c.noname.html

--KeithDerrick


CategoryCpp


EditText of this page (last edited October 16, 2002) or FindPage with title or text search