-
current is a pointer to an object and therefore you'll need to dereference it properly to call the operator().
Apparently brackets make a difference here: 1) dereference current (and current only), 2) call operator() on the dereferenced object.
In addition the base-class needs to declare a virtual float operator()(int), otherwise you'll be trying to call a method through a base pointer that the base class doesn't have.
-
Actually hey, it's possible to use a class to emulate a function pointer:
Code:
typedef float (CallbackPtr)(float);
class CCallback
{
public:
CCallback(CallbackPtr CallbackFnc) : m_Callback(CallbackFnc) { }
operator CallbackPtr* () { return m_Callback; }
private:
CallbackPtr* m_Callback;
};
float Help2(float n) { return n; }
void Help()
{
CCallback c = &Help2;
float f = c(1.0f);
}
Pretty cool. I'll leave you to experiment on that if you wish to use it.
The original error was also that the constructor only takes std::string and not an int
-
What I'm really doing is modeling a function as you would write it on paper. In order to do that I need the "whole" function for each operation. For this it has to be in a vector of functions
so something like
cos(x) + x^2 + ax * 2
would go into a vector and look like
Code:
funcallback Array
0|cosCallback|
1|powCallback(2)|
2|multCallback|
3|identCallback(2)|
well i solved calling it, I just made the notationand it works.
Elysia C++ offers function callbacks, which is what I'm using, so you don't really need to do all that for function objects, just use the overloaded operator() in a class.
-
ok so I think I solved the situation, here will be the basic idea of my programs
Code:
class FunCallback
{
protected:
std::string name; ///<the name of the function
double input; ///<the input of the function
public:
FunCallback(std::string label);
virtual double operator()(double in);
operator std::string();
virtual ~FunCallback();
};
//would basically represent a single constant that returns it's input value upon
class IdCb: public FunCallback
{
public:
IdCb(double in);
double operator()(double in);
};
I have others like these. Some that take constructors, some that don't. THis would allow me to create a factory class that reads an input file and generate a function definition via an array of these things.
They'll have to all be doubles because you can't have overloaded type returns.