[ad_1]
It exhibits 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 capabilities 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 applied these capabilities 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 exhibits these errors.Why?
You didn’t implement the strategies. What you probably did is use is lambda expressions to create nameless capabilities.
This is a lambda expression:
listener->onKeyPressed = [=](cocos2d::EventKeyboard::KeyCode keyCode, Event* occasion) {
keys[keyCode] = true;
};
So, you’ve gotten 2 choices.
Option 1 – Get rid of the declarations within the header file, since you’re not implementing them as class member capabilities.
Option 2 – Don’t use lambda expressions, and implement the capabilities.
Either works.
[ad_2]