Tile Map(unknown reason for unresolved external symbols)

So I tried to make a tile map function to display my map as tiles. I keep getting unresolved external symbol errors, I've included the header file, and used every declaration in it, but to be completely honest this is mostly just a try to see if I could do it, and so far I'm failing. So if you can see why I'm getting the errors, please let me know.

header tileMap.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<SFML/Graphics.hpp>
#include<iostream>
#include<fstream>
#include<string>
#include<cctype>
#include<vector>

class tileMap
{
	static sf::Texture tileTexture;
	static std::vector<sf::Vector2i> tempMap;
	static std::string tileLocation;

public:
	static void mTileMap();
	static sf::Sprite tiles;
	static std::vector<std::vector<sf::Vector2i>> map;
};


source tileMap.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "tileMap.h"


void tileMap::mTileMap(void)
{
	std::ifstream openfile("Map.txt");

	if(openfile.is_open())
	{
		openfile >> tileLocation;
		tileTexture.loadFromFile(tileLocation);
		tiles.setTexture(tileTexture);
		
		while(!openfile.eof())
		{
			std::string str;
			openfile >> str;

			char x = str[0], y = str[2];

			if(!isdigit(x) || !isdigit(y))
				tempMap.push_back(sf::Vector2i(-1, -1));
			else
				tempMap.push_back(sf::Vector2i(x - '0', y - '0'));

			if(openfile.peek() == '\n')
			{
				map.push_back(tempMap);
				tempMap.clear();
			}
		}
		map.push_back(tempMap);
	}
}


source main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <SFML/Graphics.hpp>
#include "tileMap.h"

int main(void)
{
	sf::RenderWindow window(sf::VideoMode(640, 480, 32), "TileMap Engine");

	while(window.isOpen())
	{
		sf::Event event;

		while(window.pollEvent(event))
		{
			if(event.type == sf::Event::Closed)
			window.close();
		}
		tileMap::mTileMap();

		window.clear();

		for(int i = 0; i < tileMap::map.size(); i++)
		{
			for(int j = 0; j < tileMap::map[i].size(); j++)
			{
				if(tileMap::map[i][j].x != -1 && tileMap::map[i][j].y != -1)
				{
					tileMap::tiles.setPosition(j * 32, i * 32);
					tileMap::tiles.setTextureRect(sf::IntRect(tileMap::map[i][j].x *32, tileMap::map[i][j].y *32, 32, 32));
					window.draw(tileMap::tiles);
				}
			}
		}

		window.display();
	}
	return 0;
}


output message:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1
1>  main.cpp
1>c:\users\twiggystardust\documents\visual studio 2010\projects\tilemapengine\main.cpp(21): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\twiggystardust\documents\visual studio 2010\projects\tilemapengine\main.cpp(23): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\twiggystardust\documents\visual studio 2010\projects\tilemapengine\main.cpp(27): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\twiggystardust\documents\visual studio 2010\projects\tilemapengine\main.cpp(27): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::Sprite tileMap::tiles" (?tiles@tileMap@@2VSprite@sf@@A)
1>tileMap.obj : error LNK2019: unresolved external symbol "public: static class sf::Sprite tileMap::tiles" (?tiles@tileMap@@2VSprite@sf@@A) referenced in function "public: static void __cdecl tileMap::mTileMap(void)" (?mTileMap@tileMap@@SAXXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: static class std::vector<class std::vector<class sf::Vector2<int>,class std::allocator<class sf::Vector2<int> > >,class std::allocator<class std::vector<class sf::Vector2<int>,class std::allocator<class sf::Vector2<int> > > > > tileMap::map" (?map@tileMap@@2V?$vector@V?$vector@V?$Vector2@H@sf@@V?$allocator@V?$Vector2@H@sf@@@std@@@std@@V?$allocator@V?$vector@V?$Vector2@H@sf@@V?$allocator@V?$Vector2@H@sf@@@std@@@std@@@2@@std@@A)
1>tileMap.obj : error LNK2001: unresolved external symbol "public: static class std::vector<class std::vector<class sf::Vector2<int>,class std::allocator<class sf::Vector2<int> > >,class std::allocator<class std::vector<class sf::Vector2<int>,class std::allocator<class sf::Vector2<int> > > > > tileMap::map" (?map@tileMap@@2V?$vector@V?$vector@V?$Vector2@H@sf@@V?$allocator@V?$Vector2@H@sf@@@std@@@std@@V?$allocator@V?$vector@V?$Vector2@H@sf@@V?$allocator@V?$Vector2@H@sf@@@std@@@std@@@2@@std@@A)
1>tileMap.obj : error LNK2001: unresolved external symbol "private: static class std::vector<class sf::Vector2<int>,class std::allocator<class sf::Vector2<int> > > tileMap::tempMap" (?tempMap@tileMap@@0V?$vector@V?$Vector2@H@sf@@V?$allocator@V?$Vector2@H@sf@@@std@@@std@@A)
1>tileMap.obj : error LNK2001: unresolved external symbol "private: static class sf::Texture tileMap::tileTexture" (?tileTexture@tileMap@@0VTexture@sf@@A)
1>tileMap.obj : error LNK2001: unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > tileMap::tileLocation" (?tileLocation@tileMap@@0V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
1>C:\Users\TwiggyStardust\documents\visual studio 2010\Projects\tileMapEngine\Debug\tileMapEngine.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Static data members need to be defined in a source file. For example,
1
2
3
4
5
6
7
//header
class A{
    static int foo;
};

//source
int A::foo(0);
ok, if I make the members not static: I changed the tileMap.h file to this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<SFML/Graphics.hpp>
#include<iostream>
#include<fstream>
#include<string>
#include<cctype>
#include<vector>

class tileMap
{
public:
	void mTileMap();
	sf::Texture tileTexture;
	std::vector<sf::Vector2i> tempMap;
	std::string tileLocation;
	sf::Sprite tiles;
	std::vector<std::vector<sf::Vector2i>> map;
};


now, how do I call map and tiles in the main file? I tried using
1
2
tileMap::map
tileMap::tiles


and just using the name of each, but neither works. I'm sorry this may seem simple(i possibly should have put this in beginners) but this is my first time trying to code something this ambitious without a reference.
Non-static members need an instance of the class. Following my previous example and removing the static bits,
1
2
A a;
a.foo = 5;
ok so I got it to compile and run, but the tiles don't show up...I used most of the code from this other tile map tutorial, but I wanted to separate the function into it's own, any ideas? the code is mostly the same as up there. the tut was here http://www.youtube.com/watch?v=O7lVymlZMy0
I gotta say, I really don't understand this trend of making programming "tutorials" in video form. I can't quickly copy anything, I can't search for anything, and I'm downloading far more data than I actually need.

I don't know SFML, but if I had to take a stab, I'd say your while(window.pollEvent(event)) loop holds the window open without displaying anything until the user closes it. Only then do you actually start to draw anything.
helios, I agree about the video tutorials, plus on the other side my internet is crazy slow and I have to wait about 20 minutes for a 5 minute video to load enough to watch non-stop but sometimes it still isn't enough and I have to pause it half-way through.

Anyway, I tried moving the pollEvent loop down under window.display(), but that still didn't work. So I changed the code to look almost exactly like the code in the tutorial. I did have the code from that saved in my projects, so I took a look at it and the only thing I was doing different was using an if statement where it should have been a switch. so I made it a switch, and it's still not working. I think the problem is because I'm creating an object in main.cpp, and it's not actually using the data used in the function, I'll post what I have now, maybe someone can see something.

tileMap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<SFML/Graphics.hpp>
#include<iostream>
#include<fstream>
#include<string>
#include<cctype>
#include<vector>

class tileMap
{
public:
	void mTileMap();
	sf::Texture tileTexture;
	std::vector<sf::Vector2i> tempMap;
	std::string tileLocation;
	sf::Sprite tiles;
	std::vector<std::vector<sf::Vector2i>> map;
};


tileMap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "tileMap.h"


void tileMap::mTileMap()
{
	std::ifstream openfile("Map.txt");

	if(openfile.is_open())
	{
		openfile >> tileLocation;
		tileTexture.loadFromFile(tileLocation);
		tiles.setTexture(tileTexture);
		
		while(!openfile.eof())
		{
			std::string str;
			openfile >> str;

			char x = str[0], y = str[2];

			if(!isdigit(x) || !isdigit(y))
				tempMap.push_back(sf::Vector2i(-1, -1));
			else
				tempMap.push_back(sf::Vector2i(x - '0', y - '0'));

			if(openfile.peek() == '\n')
			{
				map.push_back(tempMap);
				tempMap.clear();
			}
		}
		map.push_back(tempMap);
	}
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <SFML/Graphics.hpp>
#include "tileMap.h"

int main(void)
{
	sf::RenderWindow window(sf::VideoMode(640, 480, 32), "TileMap Engine");

	while(window.isOpen())
	{
		sf::Event event;

		while(window.pollEvent(event))
		{
			switch(event.type)
			{
			case sf::Event::Closed:
				window.close();
				break;
			}
		}
		
		window.clear();

	
		tileMap mtilemap;
		void mTileMap();

		for(int i = 0; i < mtilemap.map.size(); i++)
		{
			for(int j = 0; j < mtilemap.map[i].size(); j++)
			{
				if(mtilemap.map[i][j].x != -1 && mtilemap.map[i][j].y != -1)
				{
					mtilemap.tiles.setPosition(j * 32, i * 32);
					mtilemap.tiles.setTextureRect(sf::IntRect(mtilemap.map[i][j].x *32, mtilemap.map[i][j].y *32, 32, 32));
					window.draw(mtilemap.tiles);
				}
			}
		}

		window.display();
	}
}

void mTileMap()
{
	return mTileMap();
}


i'm not even sure if that last bit in main is necessary or if it's even doing anything, I just thought maybe that would bring the data from it's function into main... any help is gladly appreciated. And helios, thanks for the help so far
My guess would be lines 25 and 26 in main. Move line 25 out of the main loop, above line 8. Line 26 is a function declaration.
And this
1
2
3
4
void mTileMap()
{
	return mTileMap();
}
can't be good.
So naraku, i took that out. And I did try moving line 25 above line 8, it still didn't work. I did get it working though. I moved everything in main into tileMap.cpp and just wrote

1
2
3
tileMap mtilemap;

mtilemap.mTileMap();


in main. I originally didn't want to do this, because I still wanted all the window stuff in main. I'm thinking I may be able to move some stuff around and get it working still, I think all I really needed to keep in the tileMap.cpp was the for loops. I don't have the time to try this today but I'll update it tomorrow and let you all know. Thanks again though.
Topic archived. No new replies allowed.