views:

135

answers:

3

I'm trying to set a static pointer variable in a class but I'm getting these errors for each variable I try to set.

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2040: 'xscroll' : 'int' differs in levels of indirection from 'float *'

error C2440: 'initializing' : cannot convert from 'float **' to 'int'

Here is the code Enemy.h

#include <windows.h>
#include "Player.h"

class Enemy
{
public:
Enemy(float xPos, float yPos);
Enemy(void);
~Enemy(void);

//update the position of the user controlled object.
void updatePosition(float timeFactor);

//loads all the enemy textures
void static loadTextures();

//creates a set number of enemies
void static createEnemies(int numEnemies, Enemy * enemyArray);

GLuint static enemyTex;
static float * xscroll;
static float * yscroll;
static Player * player;

private:
bool checkCollison(float x, float y, int radius);

float XPos;
float YPos;

};

trying to set variables

Enemy::xscroll = &xscroll;
Enemy::yscroll = &yscroll;
Enemy::player = &player;
+1  A: 

Assuming those are the definitions, you need to include the type (that's the first error):

float *Enemy::xscroll = ...;
Player *Enemy::player = ...;

As for the second errors, it appears that xscroll is not a float, so &xscroll is not a float * and therefore cannot be assigned to Enemy::xscroll. You need to make sure the types of your variables are correct.

R Samuel Klatchko
Ben Voigt
@BenVoigt - good catch. That said, any clue where the `float **` in the third error comes from?
R Samuel Klatchko
Ben Voigt
+1  A: 

I think you're mixing up initialization with assignment. All class static variables have to be defined once, from global scope (i.e. the definition is outside any class or function, can be in a namespace however) and can be initialized at that time. This definition looks just like the definition of any global variable, type identifier = initializer; except that the identifier includes the scope operator ::.

Ben Voigt
A: 

Maybe writing setter/getter public static methods to change variables is best way? And move xscroll and others sto private.

It's more beatiful solution, i think, and code is going to be more simple.

lph0
All static variables still need to be defined outside the class.
Ben Voigt