Monday, October 03, 2005 |
|
|
Effective C++, Third Edition, by Scott Meyers, contains a number of fundamental C++ guidelines that should be read by all C++ programmers. Having already read a previous edition of Effective C++, my expectation was that I would get a nice reminder of things I already knew. My hope was that I’d learn a few things that I didn’t already know, or had forgotten; here are some of those things:
- You can use the member initialization list of a constructor definition even when you want to default construct a data member (p. 29).
- A classic implementation of the copy assignment operator takes its argument by value (to make a copy of it) and then calls
swap on that argument (p. 56).
- Since compilers can reorder operations within a statement, very surprising things can happen in the face of exceptions (p. 76).
- Prefer non-member non-friend functions to member functions (p. 98). I remember this controversial item from the last edition, but it was good to read his rationale again.
- There are very peculiar rules about the
swap function. You need to consult item 25 (p. 106) before you attempt to write a non-throwing swap function for your classes. Even calling the swap function is complicated – you must not call std::swap directly, but should instead call it like this: using std::swap; ... swap(obj1, obj2);
- It never occurred to me to use an “interface class” for a single concrete class, merely to reduce compilation dependencies (p. 145).
- Use
using declarations to avoid hiding inherited names; you rarely want to hide inherited member functions when you add a new overload, but that’s what happens in C++ (p. 159).
- Include a definition for a pure virtual function if you want to provide a default implementation that must be explicitly requested (p. 167).
- I didn’t realize that “accessing names in templated base classes” was a problem; you’d think I’d have run into that before (item 43, p. 207).
- I also never realized that I’d need to “define non-member functions inside templates when type conversions are desired.” The only way to do that is with a friend function, even if the function doesn’t need special access to your members (item 46, p. 222).
|
10/3/2005 9:23:51 AM (Pacific Daylight Time, UTC-07:00) | | Books
|
|
|
|
|
|
|
| Archive |
| March, 2008 (1) |
| January, 2008 (1) |
| September, 2007 (1) |
| July, 2007 (1) |
| June, 2007 (3) |
| May, 2007 (2) |
| January, 2007 (2) |
| December, 2006 (1) |
| November, 2006 (2) |
| August, 2006 (6) |
| July, 2006 (3) |
| May, 2006 (4) |
| April, 2006 (2) |
| March, 2006 (1) |
| February, 2006 (1) |
| January, 2006 (1) |
| December, 2005 (2) |
| November, 2005 (5) |
| October, 2005 (11) |
| September, 2005 (7) |
| August, 2005 (1) |
| July, 2005 (2) |
| June, 2005 (2) |
| April, 2005 (5) |
| March, 2005 (11) |
| February, 2005 (6) |
| January, 2005 (2) |
| December, 2004 (1) |
| November, 2004 (1) |
| October, 2004 (3) |
| September, 2004 (1) |
| August, 2004 (5) |
| July, 2004 (10) |
| June, 2004 (3) |
| May, 2004 (5) |
| April, 2004 (3) |
| March, 2004 (10) |
| February, 2004 (10) |
| January, 2004 (15) |
| December, 2003 (1) |
| November, 2003 (2) |
| October, 2003 (13) |
| September, 2003 (20) |
| August, 2003 (24) |
|
|
|
|