The new standard fixes this by allowing Delegating Constructors. Basically one constructor can now call another one from the same class in its place.
Heres an example:
//compile with g++ -std=c++11 $< -o $@ #include <iostream> class DelgateConstructor { std::string str_; public: DelgateConstructor(char* s) : str_(s) { std::cout << "Working...\n"; } DelgateConstructor() : DelgateConstructor("Here we are") { std::cout << str_ << "\n"; } }; int main() { DelgateConstructor whatever; }This results in this output:
Working... Here we are
No comments:
Post a Comment