home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-

New Paste :: Recent Pastes:: No Line Numbers

ctor init list by CraZyLeGs
Use initializer lists.
Consider the following class:
class Vehicle
Vehicle(const std::string &name) // Don't do this!
mName = name;
std: : string mName;
Because member variables are constructed before the body of the constructor is
invoked, this code calls the constructor for the string mName, and then calls the
= operator to copy in the object's name. What's particularly bad about this example
is that the default constructor for string may well allocate memory