-
Wanted to add one more option for Customer (if the validation is simple) picking 666 as a "sensible" default. I guess you might also use static const members instead of magic values.
Code:
class Customer
{
public:
Customer(unsigned pw):
m_pw( pw < 500 ? pw : 666)
{}
//...
};
-
A vector is pretty much always better than a dynamic array, since a vector is just a really good implementation of a dynamic array. If you find better performance with the dynamic array, chances are you aren't using the vector correctly.
If you know at compile time the size of the array, then a statically sized array might provide some performance benefits (if you really need them), but that's not the problem being discussed in this thread.
As far as the initializer list, if you have to do some checking on the validity of the input, then of course you would put that inside the body of the constructor. However, that is a lot more rare than you would think. Besides, it only applies to constructor parameters, and you often have a lot more member variables that are not initialized via those parameters.
Even if you don't put the member variable in the initialization list, it will still be initialized there. For built-in types like int this does nothing, but for class types a default constructor will be called. So for consistency and clarity people generally put all memeber variable initialization into that list.
-
I was reading this on linline functions and it suggests the very same thing for inlining. It's a good read if anyone in is inclined:
http://www.cs.cmu.edu/~gilpin/c++/performance.html