I have a (for me) complex object with about 20 data member, many of which are pointer to other classes. So for the constructor, I have a big long, complex initialization list. The class also has a dozen different constructors, reflecting the various ways the class can be created. Most of these initialized items are unchanged between each of these different constructors.
My concern here is that I now have a large chuck of copied (or mostly copied) code which, if I need to add a new member to the class, may not make it into each of the constructor initialization lists.
class Object
{
Object();
Object(const string &Name);
Object (const string &Name, const string &path);
Object (const string &Name, const bool loadMetadata);
Object (const string &Name, const string &path, const bool loadMetadata);
}
Object::Object() :
name(),
parent_index (0),
rowData (new MemoryRow()),
objectFile (),
rows (new MemoryColumn (object_constants::RowName, OBJECTID, object_constants::ROWS_OID)),
cols (new MemoryColumn (object_constants::ColName, OBJECTID, object_constants::COLS_OID)),
objectName (new MemoryColumn(object_constants::ObjName, STRING, object_constants::short_name_len, object_constants::OBJECTNAME_OID)),
parent (new MemoryColumn(object_constants::ParentName, STRING, object_constants::long_name_len, object_constants::PARENT_OID)),
parentIndex (new MemoryColumn(object_constants::ParentIndex, OBJECTID, object_constants::PARENTINDEX_OID)),
childCount (new MemoryColumn (object_constants::ChildCount, INTEGER, object_constants::CHILD_COUNT_OID)),
childList (new MemoryColumn (object_constants::ChildList, STRING, object_constants::long_name_len, object_constants::CHILD_OID)),
columnNames (new MemoryColumn (object_constants::ColumnNames, STRING, object_constats::short_name_len, object_constants::COLUMN_NAME)),
columnTypes (new MemoryColumn (object_constants::ColumnTypes, INTEGER, object_constants::COLUMN_TYPE)),
columnSizes (new MemoryColumn (object_constants::ColumnSizes, INTEGER, object_constants::COLUMN_SIZE))
{}
Then repeat as above for the other constructors. Is there any smart way of using the default constructor for this, then modifying the results for the other constructors?