undefined reference to static private member

closed account (1v5E3TCk)
Hi guys,
It has been too long since I was last here to ask a question. Okey here is my problem:

I am coding a map editor for my friends game and I have a problem. When I try to ...(I dont know the verb, sorry :D) static private variable in my class it gives the error in title.

here is my code:

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
  #ifndef MAP_HPP_INCLUDED
#define MAP_HPP_INCLUDED

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <vector>

using namespace std;

class Map
{
private:
    static int size;
    static vector<sf::Sprite> sprites;

public:

    static bool isOpen;

    static void install(int getSize)
    {
        size = getSize;
        sprites.resize( size );
    }

    static void closer()
    {
        isOpen = false;
    }

    static void opener()
    {
        isOpen = true;
    }

    static bool iAmTired()
    {
        return isOpen;
    }
};

#endif // MAP_HPP_INCLUDED 
As Ne55 already mentioned you must create the static objects outside of the class by using the scope:

 
int Map::size = 0;



Don't forget to do this with the vector as well

http://www.learncpp.com/cpp-tutorial/811-static-member-variables/.
closed account (1v5E3TCk)
How can I access private members from outside the class? It is private :S
Initializing and accessing are different.
To elaborate on what giblet said, you access a member to change its value, or use its value in some greater scheme, but you initialize a member to a default value inside the scope of the class.

That's what the double-colon :: operator does. It's called the scope operator, and even if you're initializing or defining something outside of the scope delimiters of a class {} aka curly braces, you're still technically in the scope of the class if you use the scope operator to specify that you are.

Hence Map::size which can be read as "Map member size."
closed account (1v5E3TCk)
Thanks for your helps
Topic archived. No new replies allowed.