我想知道你是否可以使用emplace_back将项目存储到一个向量中,这是一种从向量所期望的类派生的类型.
例如:
struct fruit
{
std::string name;
std::string color;
};
struct apple : fruit
{
apple() : fruit("Apple", "Red") { }
};
Run Code Online (Sandbox Code Playgroud)
别的地方:
std::vector<fruit> fruits;
Run Code Online (Sandbox Code Playgroud)
我想在向量中存储apple类型的对象.这可能吗?