Factory pattern C++