It exhibits the errors:
1>first.obj : error LNK2001: unresolved exterior image
“public: digital void __thiscall first::onKeyPressed(enum cocos2d::EventKeyboard::KeyCode,class cocos2d::Occasion *)” (?onKeyPressed@first@@UAEXW4KeyCode@EventKeyboard@cocos2d@@PAVEvent@4@@Z)
1>first.obj : error LNK2001: unresolved exterior image
“public: digital void __thiscall first::onKeyReleased(enum cocos2d::EventKeyboard::KeyCode,class cocos2d::Occasion *)” (?onKeyReleased@first@@UAEXW4KeyCode@EventKeyboard@cocos2d@@PAVEvent@4@@Z)
1>D:cocos2d-x-3.17testsgame1proj.win32Debug.win32game1.exe : deadly error LNK1120: 2 unresolved exterior instructions
The right way to resolve?
Implement the lacking strategies.
I’ve declared these capabilities within the first.h file:
void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Occasion* occasion);
void onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Occasion* occasion);
I’ve carried out these capabilities in first.cpp file,
auto listener = EventListenerKeyboard::create();
listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Occasion* occasion) {
keys[keyCode] = true;
};
listener->onKeyReleased = [=](cocos2d::EventKeyboard::KeyCode keyCode, Occasion* occasion) {
keys[keyCode] = false;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
It nonetheless exhibits these errors.Why?
You didn’t implement the strategies. What you probably did is use is lambda expressions to create nameless capabilities.
It is a lambda expression:
listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Occasion* occasion) {
keys[keyCode] = true;
};
So, you have got 2 choices.
Possibility 1 – Do away with the declarations within the header file, since you’re not implementing them as class member capabilities.
Possibility 2 – Don’t use lambda expressions, and implement the capabilities.
Both works.