Jump to content
  • Advertisement
Sign in to follow this  
A_B

function pointer

This topic is 3029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)


Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Not sure, but try changing this:

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


to:

void (* cOpenGLLib::inputFunc)();

EDIT: Made a correction.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!