Jump to content
  • Advertisement
Sign in to follow this  
BreathOfLife

function pointer question

This topic is 3788 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

OK, Im getting a few unresolved externals for some code, and I cant for the life of me figure out why. My googling didnt find anything I could figure out my situation from. Im running VS 2008 on a vista notebook. In a .h there is this:
typedef struct _input_event
{
	_input_event();
	~_input_event();

	int type;
	int key;

} INEVENT, *LPINEVENT;

and in the matching .cpp:
void (*EventHandler)(LPINEVENT) = NULL;


//in here some code to set a void func that takes a LPINEVENT

	if ( !(old_keystates == new_keystates) )
	{
		LPINEVENT inevent = new INEVENT;
		for (key = 0; key < 256; key++)
		{
			if ( (old_keystates[key] == STATE_UP) && (new_keystates[key] == STATE_DOWN) )
			{
			inevent->type = KEY_PRESS;
			inevent->key = key;
			(*EventHandler)(inevent);
			}
		}
		delete inevent;
	}
}

The two errors Im getting are as follows: 1>SYS_INPUT.obj : error LNK2001: unresolved external symbol "public: __thiscall _input_event::_input_event(void)" (??0_input_event@@QAE@XZ) 1>SYS_INPUT.obj : error LNK2001: unresolved external symbol "public: __thiscall _input_event::~_input_event(void)" (??1_input_event@@QAE@XZ) (naturally and a third telling me there is these 2) I havent used function pointers all that terribly much, but when trying the examples in that "learn c++ in 21 days" they worked fine.

Share this post


Link to post
Share on other sites
Advertisement
The linker is telling you it cannot find the implementation of struct _input_event's constructor or destructor. Either define them inline in the header, or inside one of your cpp files.

[edit]

Also I thought I'd add some points regarding writing idiomatic C++ code. In C++ we do not typedef structs. This is done in C because subsequent declarations of the struct are required to be prefixed with the struct, keyword and this is considered cumbersome. For example:


struct foo
{
....
};

struct foo myFoo;


However in C++ you can omit the struct keyword in subsequent declarations: foo myFoo;

Lastly in C++ we (generally) prefer to use function objects over function pointers. Additionally the boost library provides boost::bind and boost::function, which provide a fantastic function objects implementation.

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!