Question: I am trying to use shared\_ptr with my class but for some reason I get segfault. Maybe I am doing something stupid. 

```
#include <tr1/memory>
#include <iostream>
class Dataset ;
typedef int DataClass;
class Dataset_Impl{
    friend class Dataset ;
    DataClass *dc;
    Dataset_Impl(){dc = new DataClass[10];}
    public:
    void getSubset(Dataset_Impl* &dObj){
        dObj = new Dataset_Impl();  //Causing segfault when using shared_ptr
        /*copy subset of 'dc' to dObj->dc and return*/std::cout<<"Copied subset";
    }
};
class Dataset{
    Dataset_Impl *d;
    public:
        Dataset (){};
        inline void const getSubset(Dataset &dObj) const{d->getSubset(dObj.d);}
};
int main(){
    Dataset m1,subset1;std::shared_ptr<Dataset> subset2;
    m1.getSubset(subset1);
    m1.getSubset((*subset2)); //Causing segfault
}

```

Answer: 
You haven't created an object; `subset2` is a null pointer. You need to create an object for it to manage:

```
std::shared_ptr<Dataset> subset2(new Dataset);

```
For information there is a dedicated function to create a `shared_ptr` on a new allocated object , in your case: 

```
std::make_shared<Dataset>()

```

This will call `Dataset()` constructor. If you have a second constructor, let's say `Dataset(int)`, you may write `std::make_shared<Dataset>(i)` with an integer i.