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: 
I think you mean a smart function pointer, and for that there is since C++11, `std::function`, so how about this:

```
#include <functional>
#include <iostream>

double a(int i){
    return i;
}

double b(int i){
    return i * 2;
}

double c(double d, int i){
    return i - d;
}

int main() {
    std::function<double(int)> func = a;
    std::cout << func(42) << std::endl;//Output 42

    func = b;
    std::cout << func(42) << std::endl;//Output 84

    //func = c; //Error since c has a different signature (need one more argument), #type safety

    func = std::bind(c, 5 ,std::placeholders::_1); //func stores the needed 2nd argument
    std::cout << func(42) << std::endl;//Output 37

}

```
**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.