Jump to content

  • Log In with Google      Sign In   
  • Create Account

'Unresolved external symbol' when using static struct in static method


Old topic!
Google, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Nick C.   Members   -  Reputation: 192

Like
0Likes
Like

Posted 11 November 2012 - 09:39 AM

Hello everyone

I'm writing an input managing class, and I've stumbled upon a problem right now. I've been trying to fix it for a long time, but I just don't see the problem. It's probably a minor detail (like always.. -.-), but I would really apreciate it if someone could take a look at it.

The error I'm getting is:

Error 13 error LNK2001: unresolved external symbol "private: static struct Input::Keyinfo * Input::KeyinfoArr" (?KeyinfoArr@Input@@0PAUKeyinfo@1@A) C:\Nick\D3D projects\DVD\Code\Chapter 25 Character Animation\SkinnedMesh\InputManager.obj

[source lang="cpp"]header file:struct Input{//...some codepublic: enum Action{ MOVEFORWARD, MOVEBACKWARD, STRAFELEFT, STRAFERIGHT, JUMP}; static bool AllowAction(Action action);private: //...some code static const int ACTIONCOUNT = 5; // amount of possible controls/actions struct Keyinfo { Action action; int code; // virtual-key code associated with action bool pressed; bool down; }; static Keyinfo KeyinfoArr[ACTIONCOUNT];};cpp file://...some codebool Input::AllowAction(Action action){ for (int i = 0; i < ACTIONCOUNT; ++i) { if (KeyinfoArr[i].action == action) {if ((KeyinfoArr[i].action == Action::MOVEFORWARD ||KeyinfoArr[i].action == Action::MOVEBACKWARD ||KeyinfoArr[i].action == Action::STRAFELEFT ||KeyinfoArr[i].action == Action::STRAFELEFT)&& KeyinfoArr[i].down) return true; if (KeyinfoArr[i].action == Action::MOVEFORWARD && KeyinfoArr[i].pressed) return true; } } return false;}[/source]

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9603

Like
1Likes
Like

Posted 11 November 2012 - 09:51 AM

When you declare a static variable in a class, you still need to define it in a source file. In one source file you need to put:
Keyinfo Input::KeyinfoArr[ACTIONCOUNT];


#3 e‍dd   Members   -  Reputation: 2105

Like
1Likes
Like

Posted 11 November 2012 - 10:26 AM

And you'll want to initialise those Keyinfos at the point of that definition too, else you're in for some trouble.

Edited by e‍dd, 11 November 2012 - 10:29 AM.


#4 Nick C.   Members   -  Reputation: 192

Like
0Likes
Like

Posted 11 November 2012 - 11:01 AM

When you declare a static variable in a class, you still need to define it in a source file. In one source file you need to put:

Keyinfo Input::KeyinfoArr[ACTIONCOUNT];


Stupid of me. Works like a charm now, thanks :)




Old topic!
Google, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS