Okie dokie. Hi everyone!
I need help using function pointers inside of classes. I have a class, called CGraph, that has two functions in it for building colors, BuildColor15 and BuildColor16 (each of which takes three UCHAR's).
I decided that instead of having switch statements all over the place, I'd make a function pointer inside the CGraph class called fnBuildColor. Could someone please show me the correct syntax for declaring, assinging, and using them? And could you write my entire game for me?
Seriously, though, I've been trying for quite a while to get it right.
The code I have currently looks like this:
Declaration (in the public section of CGraph):
USHORT (CGraph::*fnBuildColor) (BYTE, BYTE, BYTE); // Function pointer to the build color functions
Assignment (In the constuctor of CGraph):
CGraph::fnBuildColor = BuildColor15;
Utilisation (In WinMain(), with all the right headers):
CGraph* Screen;
Screen = new CGraph(640,480);
USHORT blah = Screen->fnBuildColor(5,7,8);
The utilisation code gives me an 'undeclared identifier' error, but the compiler isn't complaining about other things. I remember that I somehow made the 'indeclared udentifier' error go away with some different declaration syntax, and then got a 'term does not evaluate to a function' error. Please help, I want to try to make this work.
I could probably work around using function pointers at all in this problem, but I want to see how they work and everything, so this seems like a good opportunity.
-Edit- Made a little typo which might have made you assume soemthing totally obvious was wrong, but nope, the problem's still there -
Trigon
I like food.
Edited by - TrigonLoki on 5/7/00 5:29:38 PM