function pointer

Started by
3 comments, last by A_B 14 years ago
Hi, I wanted to pass a function pointer of an imput funcion to a window class which contains the window procedure. The class:

class cOpenGLLib
{
private:
        ...
	//the window procedure
	static LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	//The external function that determines what to do with input
	static void (*inputFunc)();
        ...
public:
        //The function to which a function pointer is passed
        void MakeWindow(void (&inputFunction)(void));
};


In the cpp file:

//THE WINDOW PROCEDURE---------------------------------------------------------------------------//
LRESULT CALLBACK cOpenGLLib::WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	inputFunc();
	
	return DefWindowProc(hWnd, message, wParam, lParam);	
}
//define the input function
static void *(cOpenGLLib::*inputFunc)();


void cOpenGLLib::MakeWindow(void(&inputFunction)(void))
{
	//pass the iputfunction to the class' private input function
	inputFunc = inputFunction;
        ...
}

In the main.cpp file:

cOpenGLLib cOGL = cOpenGLLib::getInstance();

//input function
void input()
{
	switch (cOGL.msg.message)
	{
	case WM_KEYDOWN:
		PostMessage(cOGL.hWnd, WM_DESTROY, 0, 0);
		break;
	}
}

int WINAPI WinMain(...)
{
	void (*inputpntr)();
	inputpntr = &input;
	cOGL.MakeWindow(*inputpntr);
        ...
}


I compile the class to a lib file, which has no errors, but when i try to compile the main.cpp file, I get an unresolved external symbol for the inputFunc()

OGLL.lib(OGLL.obj) : error LNK2001: unresolved external symbol "private: static void (__cdecl* cOpenGLLib::inputFunc)(void)" (?inputFunc@cOpenGLLib@@0P6AXXZA)


Advertisement
compare the return types of:

static void (*inputFunc)();

and

static void *(cOpenGLLib::*inputFunc)();

[smile]
[size="1"]
Thx for the help.
Changed that but I still get the same error, you really got my hopes up by spotting that one though :D.

Thanks
Alex
Not sure, but try changing this:

//define the input functionstatic void *(cOpenGLLib::*inputFunc)();


to:

void (* cOpenGLLib::inputFunc)();

EDIT: Made a correction.
Why you must be my lord and saviour, thanks Gage64!

This topic is closed to new replies.

Advertisement