use a callback in a class
I am a very old coder, write c before, that's syntax error, that I do not know how to do:
compiler tolled me
'dInv' was not declared in this scope|
please help me, the document on web is to new to me, I can not understand.
Thank you!
1 2 3 4 5 6 7 8
|
class A{
private:
bool Compare(bool (*)(const double*));
};
bool A::Compare(bool (*PriceMatch)(const double *dInv)){
return (*PriceMatch)(*dInv);
}
|
Last edited on
The modern and probably better way to do it in modern C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <string>
#include <functional>
typedef std::function<bool(const double *)> CmpFunc;
class A
{
private:
double val;
bool Compare(CmpFunc cmp);
};
bool A::Compare(CmpFunc cmp)
{
return cmp(&val);
}
int main()
{
return 0;
}
|
Topic archived. No new replies allowed.