Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem using 'new'..(missing ; before [ )

Started by FlyingDemon May 23, 2003 at 1:10 AM 1 replies 250+ views
Original Post
FlyingDemon
FlyingDemon
I have my custom sprite class that compiled fine in devc++ but when i switched it over to msvc 6.0(i didn''t change the file at all when i switched it over) i got an error saying: csprite.h(31) : error C2143: syntax error : missing '';'' before ''['' LB.exe - 1 error(s), 0 warning(s) take a look at csprite.h
  
#ifndef __CSPRITE_H__
#define __CSPRITE_H__


typedef struct 
{
    float Delay;
    unsigned char Data[16384];
    unsigned int texID;
}s_sprite_stat;

class C_Sprite_Tag {
    public:	//values

    int numFrames;	//total number of frame in the sprite

    s_sprite_stat *Image;//holds sprite information in a 1-d array

    

    public: //functions

    //constructor

    C_Sprite_Tag(){}
    //destructor

    ~C_Sprite_Tag(){
        delete[] Image;    
    };
    //loads a sprite file("*.spr")

    void LoadSprite(char *path) {
    
        FILE *file = fopen(path,"rb");   //open the sprite file

        
        fread(&numFrames,4,1,file);   //get total number of frames

        Image = new(s_sprite_stat)[numFrames]; //<<- ERROR HERE!!!

	for(int i=0;i<numFrames;i++) {    //load sprite frames

            fread(&Image[i].Data,1,16384,file);	  
            fread(&Image[i].Delay,4,1,file);	  
            Image[i].texID = i;					 
        }
        fclose(file); // close the file

    };

    ///////////////////////////////////////

    //makes opengl textures

    void MakeTextures() {
        for(int i=0;i<numFrames;i++) {
            glGenTextures(1, &Image[i].texID);
            glBindTexture(GL_TEXTURE_2D, Image[i].texID);			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,                          GL_LINEAR);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0,    GL_RGBA, GL_UNSIGNED_BYTE, Image[i].Data);
        }
    }
};
///////////////////////////////

//declare

C_Sprite_Tag SPR_TAG_Sprite[3];
///////////////////////////////////


class C_Sprite {
    public:
    bool active;
    float deltaT;
    //C_Sprite_Tag Sprite;

    float pos[2];
    float rot;
    float size;
    int frame;
    int spriteID;
    
    public:
    C_Sprite(){}
    ~C_Sprite(){}
    
    void Activate(float x, float y,float _rot, float s, int _spriteID){
        pos[0]=x;
        pos[1]=y;
        rot = _rot;
        size=s;
        spriteID = _spriteID;
        
        deltaT = 0.0;
        active = true;
    }
    void Deactivate(){
        active = false;
        frame = 0;
    }
    void Draw()
    {
        if(active) {
			glPushMatrix();
			glBindTexture(GL_TEXTURE_2D, SPR_TAG_Sprite[spriteID].Image[frame].texID);
			glTranslatef(pos[0],pos[1],-10);
			glRotatef(-rot,0.0,0.0,1.0);
			glBegin(GL_QUADS);
           
				glTexCoord2f(0,0);
				glVertex3f(-size,size,0);
            
				glTexCoord2f(1,0);
				glVertex3f(size,size,0);
            
				glTexCoord2f(1,1);
				glVertex3f(size,-size,0);
            
				glTexCoord2f(0,1);
				glVertex3f(-size,-size,0);
			glEnd();
			glPopMatrix();
		}
    }
    void Update(float spf) {
        if(active) {
            deltaT +=spf;
            if(deltaT > SPR_TAG_Sprite[spriteID].Image[frame].Delay) {
                frame++;
                deltaT = 0.0;
            }
            if(frame == SPR_TAG_Sprite[spriteID].numFrames)
            {
                Deactivate();
            }
        }
    }
};


#endif

  
can you plz tell me whats wrong? <|||||||||||||||||||||||||||||||>
ToohrVyk
ToohrVyk
Try :

Image = new(s_sprite_stat[numFrames]);

ToohrVyk

FlyingDemon
FlyingDemon
Thanks ToohrVyk ....that fixed it.

<|||||||||||||||||||||||||||||||>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.