mardi 14 juillet 2020

std::move of an object to a shared pointer

Given the following templated class:

template<typename Container>
Class A{
public:
    A(): {}
    bool push(std::shared_ptr<Container> container) {
        ptr_vec.emplace_back(container)
    }
    void load(Container c) {
        push(std::make_shared((Container) std::move(c));        
    }
private:
    std::vector<std::shared_ptr<Container>> ptr_vec;
};

and the following code in main.cpp:

A<std::string> my_A {};
my_A.load("Hello");

I get the following error:

error: no matching function for call to 'make_shared(std::__cxx11::basic_string<char>)'

Can anyone shed some light regarding the error, and how to fix it?

Aucun commentaire:

Enregistrer un commentaire