Need to help for fix error LNK2001: unresolved external symbol

Hi Devs.
I am working in Visual C++ and having this error.

I have declared below extern lines both in .h and .cpp file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//.h File
#include <stdlib.h>
#include <cstdlib>
#include "cocos2d.h"
#include <vector>

using namespace std;
using namespace cocos2d;
..........
public:
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* createScene();
	struct Item
	{
		cocos2d::Sprite* sprite;
		int	type;
	};

	static std::vector<Item> itemArray1;

And .cpp File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
std::vector<Item> itemArray1;
.....
void HelloWorld::createAndShowByRandowm(int position, int type) {
	cocos2d::log("Push int to array: %d", position);
	switch (position)
	{
	case 1:
		pushToPositionArray(itemArray1, type);  //HERE 
		break;
	case 2:
		pushToPositionArray(itemArray2, type);
		break;
	default:
		break;
	}
}

When build in VS Express2013 a got error
Error 39 error LNK2001: unresolved external symbol "public: static class std::vector<struct HelloWorld::Item,class std::allocator<struct HelloWorld::Item> > HelloWorld::itemArray1" (?itemArray1@HelloWorld@@2V?$vector@UItem@HelloWorld@@V?$allocator@UItem@HelloWorld@@@std@@@std@@A)
Does anyone have an idea what might cause these errors?
Last edited on
1
2
..........  // <--- presumably you have something like 'class HelloWorld {' here? 
public:
Thanks for you reply. I have found the problem!
Topic archived. No new replies allowed.