ResourceManager(void (*CreateResourceFunction) (Type** resource, char* name, char* path) = NULL)
	{
		m_list = new LinkedList<Type>;
		CreateResource = CreateResourceFunction;
	}

hey - this is code for a contructer for a class (taking the code from a book I bought). What exactly is the parameter of the function? Is the parameter like a refrence to another function? CreateResource is defined as:

void (*CreateResource)(Type** resource, char* name, char* path);

as a private member.

>>Is the parameter like a refrence to another function
Yes -- it is a pointer to another function. The function can be either a normal global function or a static method of a class and must take parameters as prototyped in that line.

example:

void foo(Type** resource, char*name, char*path)
{
   // do something
}

main()
{
     ResourceManager( foo );

}

So, say I wanted someone to provide a function that performs a mathematical function on two integers that returns an integer, I would define the "variable" to hold the function as

int (*MathematicalFunction) (int num1, int num2);

Then I could make a function called add:

int Add(int addEnd1, int addEnd2)
{
return addEnd1 + addEnd2;
}

then you do

MathematicalFunction = Add;

and so

MathematicalFunction(5,6)

would return 11?

but, if I had defined Subtract:

int Subtract(int myNum1, int myNum2)
{
return myNum1 - myNum2;
}

and set that as Mathematicl function - then

MathematicalFunction(3,4)

would return -1?

This article has been dead for over six months. Start a new discussion instead.