例如,如果用户输入字符串“调制解调器”,有没有办法实例化类调制解调器的对象。
或者是否有更简单的方法。
最佳答案
std::string strText = "modem";
CBase *pBase = nullptr;
if(strText == "modem")
pBase = new CDervied1;
else
pBase = new CDervied2;
关于C++/如何根据用户输入实例化对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28531803/