Question: I am trying to create smart pointer to my function.

I have the function:

```
double returnValue(int i){
       return i;
}

```

Its pretty simple to create raw pointer:

```
double (*somePTR)(int) = &returnValue;

```

But how to make smart pointer to the function, for example `shared_ptr`?

```
auto someptr = std::make_shared<double>(&returnValue);

```

I have tried a lot of of options, but nothing works.

Answer: 
**Smart pointers exist to manage the data behind the address.**

In case of a function pointer this data is program code. If the pointer runs out of scope it can't just *delete the function*.

Smart pointers can't hold function addresses because there wouldn't be any reason for them to do so.
Not sure about use-case, maybe it is needed only because of some uniformity in processing.

`shared_ptr<>` cannot contain a pointer to function, but can contain a dynamically allocated pointer to pointer to a function:

```
double f(int i) { return i; }
typedef double(*f_ptr)(int i);

int main (int _argc, char const **_argv) {
  std::shared_ptr<f_ptr> s(new f_ptr(f));
  (*s)(2);   // okay
  s.reset();   // releases a pointer to pointer, not function
  // ...
}

```