I have a vector containing function pointers
typedef bool (*fPtr)();
vector<fPtr> AlgoDB;
The functions that I push into the vectors are defined as below
bool SAlgos1::Algo1() {
cout << "Executing Algo1" << endl;
return true;
}
The below statement is used to add the functions / pointers to the vector
this->AlgoDB.push_back((fPtr) &this->Algo1);
This being the traditional C styled function pointer usage, I am trying to use the std::function
, where the vector and the functions are modified now as below
typedef function<bool()> ffptr;
vector <ffptr> fAlgoDB;
function<bool()> SAlgos1::fAlgo1(){
cout << "Executing FAlgo1";
return true;
}
But now whenever I use the statement like this
this->fAlgoDB.push_back(fAlgo1);
or this->fAlgoDB.push_back(&fAlgo1);
(typecasting doesn't help too - this->fAlgoDB.push_back((ffptr) this->fAlgo1);
)
I get an error stating
error: taking address of temporary [-fpermissive]
and
error: could not convert 'true' from 'bool' to 'std::function<bool()>'
(even though I dont really call the function) for every alternate compilation.
How can I store the functions or function pointers in the vector? What is the compiler trying to convey?