what does this statement do? void (*update)(Blackboard&);?
im not sure what exactly is "update" but im sure "Blackboard" is a class. does this statement ring any bell for you? for example in below:
class Xclass{
public:
std::string representation;
const ModuleState* moduleState;
void (*update)(Blackboard&)
void (*create)();
void (*free)();
}
class Xclass{
public:
std::string representation;
const ModuleState* moduleState;
void (*update)(Blackboard&); // missing ;
void (*create)();
void (*free)();
}; // ; was missing
your code would not compile like this:
you need to have a forward declaration for
ModuleState and Blackboard (for example) like this:
class ModuleState;
class Blackboard;
In order to instantiate your class you need to have ModuleState and Blackboard defined somewhere in your code.
update, create, and free are pointers to static functions. Please check further down
The following is an application, of static function pointers used in a class:
class CPtr{
public:
// this is a pointer to a static - non-member - function taking 2 ints as parameters
int (*fct)(int, int);
CPtr( int (*)(int, int) );
};
// this is the static function the CPtr member
// it is passed as a parameter during instantiation
// of the CPtr object.
int max(int iA, int iB)
{
return iA > iB ? iA : iB;
}
// this is the constructor, which takes
// one argument, which is a pointer
// to the function, which should be used
// by the object
CPtr::CPtr(int (*Max)(int iA, int iB))
{
fct = Max;
}
int main(int argc, char* argv[])
{
// This is object a, instantiated with the
// function max. The function prototype
// is matching the declared function
// pointer in CPtr
CPtr a(max);
const int iA = 3, iB = 4;
// this is how the member is invoked
cout << "The bigger number between " << iA << " and " << iB << " is: " << a.fct(iA, iB)<<endl<<endl;
}
February 15th, 2010 at 9:52 am
It doesn’t have to ring bells, it’s basic C/C++ syntax.
Your class Xclass contains a public member variable called update, which is a pointer to a non-member function that returns void and takes one argument of type reference-to-Blackboard. You are missing a semicolon after it.
References :
February 15th, 2010 at 10:30 am
class Xclass{
public:
std::string representation;
const ModuleState* moduleState;
void (*update)(Blackboard&); // missing ;
void (*create)();
void (*free)();
}; // ; was missing
your code would not compile like this:
you need to have a forward declaration for
ModuleState and Blackboard (for example) like this:
class ModuleState;
class Blackboard;
In order to instantiate your class you need to have ModuleState and Blackboard defined somewhere in your code.
update, create, and free are pointers to static functions. Please check further down
The following is an application, of static function pointers used in a class:
class CPtr{
public:
// this is a pointer to a static - non-member - function taking 2 ints as parameters
int (*fct)(int, int);
CPtr( int (*)(int, int) );
};
// this is the static function the CPtr member
// it is passed as a parameter during instantiation
// of the CPtr object.
int max(int iA, int iB)
{
return iA > iB ? iA : iB;
}
// this is the constructor, which takes
// one argument, which is a pointer
// to the function, which should be used
// by the object
CPtr::CPtr(int (*Max)(int iA, int iB))
{
fct = Max;
}
int main(int argc, char* argv[])
{
// This is object a, instantiated with the
// function max. The function prototype
// is matching the declared function
// pointer in CPtr
CPtr a(max);
const int iA = 3, iB = 4;
// this is how the member is invoked
cout << "The bigger number between " << iA << " and " << iB << " is: " << a.fct(iA, iB)<<endl<<endl;
}
References :