Is it possible to be "DRY" (do not repeat yourself")? I would like to declare my class and essentially construct it later.
this code works:
// default constructor
UserInput::UserInput() {};
// other constructor
UserInput::UserInput(string title, string section, string subsection) :
title(title), section(section), subsection(subsection) {
SPLIT();
}
// i want to be "DRY", is it possible?
// this is the same code as the "other constrcutor"
void UserInput::operator()(string title, string section, string subsection) {
this->title = title;
this->section = section;
this->subsection = subsection;
SPLIT();
}
this does not work, the class ends up with blank strings:
void UserInput::operator()(string title, string section, string subsection) {
UserInput(title, section, subsection);
}
boost::optional, which lets you delay creation and makes no value a valid value, like null.