I wanted to know what I might be doing wrong here. This is my code sample. Its just a rough code sample depicting the use of function pointers.
#include <iostream>
#include <functional>
using namespace std;
std::function<std::string(std::string)> fptr;
std::string foo()
{
return fptr(); //--->statement A
}
std::string bar(std::string p)
{
return p;
}
int main()
{
fptr = std::bind(&bar,"Hello");
std::cout << foo();
}
Notice in std::bind
I did not use any placeholders and "Hello" is the parameter to the function bar
. My question is why does
return fptr();
not work. If i do the following
return fptr("Bye");
It works and returns "Hello" . (No point of passing parameter during fptr call) Why does it not work without a parameter ?
Aucun commentaire:
Enregistrer un commentaire