相关疑难解决方法(0)

在std :: make_shared中使用c ++聚合初始化

根据我的理解,下面的代码构造一个类型的对象,Foo然后将该对象移动到由分配的内存中std::make_shared

struct Foo
{
    std::string s;
    int i;
    char c;
};

int main(int argc, char* argv[])
{
    auto foo = std::make_shared<Foo>(Foo{"hello", 5, 'c' });
}
Run Code Online (Sandbox Code Playgroud)

是否可以将initialize Foo直接聚合到由std::make_shared?分配的内存中?

c++ c++11

19
推荐指数
1
解决办法
2892
查看次数

标签 统计

c++ ×1

c++11 ×1