Unresolved external symbol

It shows the errors:
1>first.obj : error LNK2001: unresolved external symbol
“public: virtual void __thiscall first::onKeyPressed(enum cocos2d::EventKeyboard::KeyCode,class cocos2d::Event *)” (?onKeyPressed@first@@UAEXW4KeyCode@EventKeyboard@cocos2d@@PAVEvent@4@@Z)
1>first.obj : error LNK2001: unresolved external symbol
“public: virtual void __thiscall first::onKeyReleased(enum cocos2d::EventKeyboard::KeyCode,class cocos2d::Event *)” (?onKeyReleased@first@@UAEXW4KeyCode@EventKeyboard@cocos2d@@PAVEvent@4@@Z)
1>D:\cocos2d-x-3.17\tests\game1\proj.win32\Debug.win32\game1.exe : fatal error LNK1120: 2 unresolved external commands

How to resolve?

Implement the missing methods.

I have declared these functions in the first.h file:

	void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event);
	void onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event);

I have implemented these functions in first.cpp file,

	auto listener = EventListenerKeyboard::create();
	listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* event) {
		keys[keyCode] = true;
	};
	listener->onKeyReleased = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* event) {
		keys[keyCode] = false;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

It still shows these errors.Why?

You didn’t implement the methods. What you did is use is lambda expressions to create anonymous functions.

This is a lambda expression:

listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* event) {
		keys[keyCode] = true;
	};

So, you have 2 options.

Option 1 - Get rid of the declarations in the header file, because you’re not implementing them as class member functions.

Option 2 - Don’t use lambda expressions, and implement the functions.

Either works.

It works now,thanks.