[ad_1]
It reveals the errors:
1>first.obj : error LNK2001: unresolved exterior image
“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 exterior image
“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.17testsgame1proj.win32Debug.win32game1.exe : deadly error LNK1120: 2 unresolved exterior instructions
How to resolve?
Implement the lacking strategies.
I’ve declared these features within the first.h file:
void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* occasion);
void onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* occasion);
I’ve carried out these features in first.cpp file,
auto listener = EventListenerKeyboard::create();
listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* occasion) {
keys[keyCode] = true;
};
listener->onKeyReleased = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* occasion) {
keys[keyCode] = false;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
It nonetheless reveals these errors.Why?
You didn’t implement the strategies. What you probably did is use is lambda expressions to create nameless features.
This is a lambda expression:
listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* occasion) {
keys[keyCode] = true;
};
So, you’ve got 2 choices.
Option 1 – Get rid of the declarations within the header file, since you’re not implementing them as class member features.
Option 2 – Don’t use lambda expressions, and implement the features.
Either works.
[ad_2]