More Notes on “Effective C++”
18 April, 2009 § 2 Comments
This is a continuation of a previous post that I started after I finished reading Effective C++ by Scott Meyers.
Item 27: Minimize casting.
It’s hard to minimize casting, so when you do have to cast, you should use the C++-style casts instead of C-style casts. The C++-style casts have distinct purposes and allow the compiler to notice incorrect usage that the C-style casts don’t show.
Item 28: Avoid returning “handles” to object internals.
If you are returning a private member variable by reference from a public function, you’ve just opened up an entry point for that private member variable to be modified without your approval. Anytime you return a private member variable, you should return it by const-reference.
Item 34: Differentiate between inheritance of interface and inheritance of implementation.
The easiest way to differentiate between interfaces and implementations is to declare your interfaces with a naming convention like IInterface. This way you can clearly see that a class is enumerable becuase it implements IEnumerable, yet if the class inherits SortedArray, then you know that it extends an implementation of a SortedArray.
[…] I started after I finished reading Effective C++ by Scott Meyers. Previously covered were parts three, two, and […]
[…] 2: Prefer C++-style casts. This was already mentioned in Item 27 of ECPP, but is reinforced within Item […]