std::shared_ptr and initializer lists

前端 未结 3 683
广开言路
广开言路 2020-12-09 16:37

The std::shared_ptr constructor isn\'t behaving as I expected:

#include 
#include 

void func(std::vector st         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 17:06

    Try this:

    auto ptr = std::make_shared(std::initializer_list{"foo", "bar", "baz"});
    

    Clang is not willing to deduce the type of {"foo", "bar", "baz"}. I'm currently not sure whether that is the way the language is supposed to work, or if we're looking at a compiler bug.

提交回复
热议问题