Error initializing static member

Hi

I try use a static object that is a member of a class, but get error:


1
2
3
4
5
Undefined symbols for architecture armv6:
  "GameObjects::splashManager", referenced from:
      AppDelegate::applicationDidFinishLaunching()       in AppDelegate.o
ld: symbol(s) not found for architecture armv6
collect2: ld returned 1 exit status


My class header is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef GameObjects_H
#define GameObjects_H

#include "SplashManager.h"

class SplashManager;

class GameObjects
{
public:
    virtual ~GameObjects() {}
    static SplashManager *splashManager;
};

#endif 


My class implementation is:

1
2
3
#include "GameObjects.h"

SplashManager *GameObjects::splashManager = 0;


I use it as:

 
GameObjects::splashManager = new SplashManager();


Can anyone help me to know what im doing wrong?
Last edited on
Try defining the static member right after the class definition.
> Can anyone help me to know what im doing wrong?

You don't seem to have specified the class implementation GameObjects.o as one of the input files to ld.
use a static factory method to initialize splashManager pointer.

an simple example on how to do that:

1
2
3
4
5
6
7
8
9
class MyClass
{
	static MyClass* getInstance() { return new MyClass; }

public:
	static MyClass* pointer;
};

MyClass* MyClass::pointer = MyClass::getInstance();


Try that patern and it should work just fine.
Last edited on
SplashManager *GameObjects::splashManager = 0;
you don't need to redefine the type of splashmenager, try to use just GameObjects::splashManager = 0; and it should work just fine.
JLBorges, you are correct.

XCode doesnt compile the code. Now its OK, thanks!
Topic archived. No new replies allowed.