If I pass the nullptr
to the std::bind
function, how I check the validity of the std::function
?
// Example program
#include <iostream>
#include <string>
#include <functional>
class A
{
std::string si;
public:
A(std::string s) : si(s) {}
int getData(std::string x) {
si += x;
return si.size(); }
};
A* getA()
{
return nullptr;
}
int main()
{
auto fun = std::bind(&A::getData, getA(), std::placeholders::_1);
if (getA() == nullptr)
std::cout << "nullptr";
std::cout << "output : " << fun("str");
return 0;
}
The above program throw the segmentation fault.