I tried to use std::shared_pointer with deleter. I tried to use a member function as the deleter. However it could not compiled. Compiler gave me a error message but I could not understand why it did not work. Does someone knows why it did not work? Thank you very much.
Simplified code is following,
#include <memory>
class MemberFunctionPointerInConstructor {
public:
MemberFunctionPointerInConstructor(void) {
std::shared_ptr<int> a = std::shared_ptr<int>(new int(1), deleter); // this line makes a compiler error message
}
void deleter(int* value) {
delete value;
}
};
The error message from compiler is following,
error: invalid use of non-static member function
std::shared_ptr<int> a = std::shared_ptr<int>(new int(1), deleter);
^
Thank you very much.