vendredi 28 juillet 2017

passing std::shared_ptr> by reference to a function

I am trying to understand the use of shared_ptrs. The simple code below

#include<iostream>
#include<vector>
#include<memory>

void funct(std::shared_ptr<std::vector<double>> & H){
    H->push_back(1.00); 
}

int main()
{
std::shared_ptr<std::vector<double>> H;
funct(H);
return 0;
}

gives me a segmentation fault which I can't seem to understand. What am I doing wrong here?

Aucun commentaire:

Enregistrer un commentaire