samedi 4 août 2018

shared_ptr of a map - compilation error

I have following piece of code.

#include <memory>
#include <map>

void GetData(std::map<int, int>** data);

int main()
{
    std::shared_ptr<std::map<int, int>> data2 = std::make_shared<std::map<int, int>>();
    GetData(data2);
    return 0;
}

void GetData2(std::shared_ptr<std::map<int, int>> data)
{
    data->insert(std::pair<int, int>(1,2));
}

But it gives compilation error.

Error C2664 'void GetData(std::map,std::allocator>> **)': cannot convert argument 1 from 'std::shared_ptr,std::allocator>>>' to 'std::map,std::allocator>> **'

What am I doing wrong here?

Aucun commentaire:

Enregistrer un commentaire