I have a question about const std::function&
as a member variable.
In the below code, I was expecting to see "2" printed out. But on my compiler (gcc c++17), I saw "1", Why?
using Fn = std::function<bool()>;
class Foo
{
public:
Foo () {}
void bar(){
if(fn_)
std::cout<<"1"<<std::endl;
else
std::cout<<"2"<<std::endl;
}
private:
const Fn& fn_ = nullptr;
};
int main()
{
Foo f;
f.bar();
}