Pointer to an array of base characters?

Started by
1 comment, last by doyleman77 11 years, 8 months ago
My CSCI class had us program a game for our final; and we had a reference game to look at for help. I just picked up game programming, and subsequently, the source to my game submission. as I was reading the header files, I came across this in the Sprite.h. It's the base class from which most entities derive. Something I dont understand is why did I have the class have a member which is a pointer to a pointer to itself (obviously a pointer to an array of itself). I know that in the virtuals, base class pointers can call functions of descendants / derived classes, but still... I can't for the life of me think why I had a member that had this, or even why I passed it intot he constructor. Here's the code:

[source lang="cpp"]#ifndef SPRITE_H
#define SPRITE_H

#include "SDL/SDL.h"
#include "img_handling.h"

class Sprite
{
protected:
Sprite** tempSprite;
int selfIndex;
float x;
float y;
int width;
int height;
SDL_Surface* image;
SDL_Rect colBox; //collision box information.
public:
Sprite()
{
}
Sprite(int sI, int xpos, int ypos, int w, int h, SDL_Surface* img, Sprite** spr)
{
x = xpos;
y = ypos;
width = w;
height = h;
image = img;
tempSprite = spr;
selfIndex = sI;
colBox.x = x;
colBox.y = y;
colBox.w = w;
colBox.h = h;
}

/********************** EMPTY VIRTUAL FUNCTIONS ************************/
virtual void move(float dt)
{
}
virtual void collide()
{
}
virtual void aniSprite()
{
}
virtual void draw(SDL_Surface* dest)
{
Draw(dest, image, x, y);
}
virtual float swapVelX()
{
return 0.0;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
int getWidth()
{
return width;
}
int getHeight()
{
return height;
}
/******** MASTER UPDATE FUNCTION ********/
void doOneTurn(float dt)
{
move(dt);
collide();
}
SDL_Rect GetRect()
{
return colBox;
}
~Sprite(){image = NULL;} //Cleanup
};

#endif[/source]


is anyone able to help me remember? I have a feeling I was a bit drunk when I did this programming. I drank a few to help calm me down on my math / csci assignments, and for the most part it helped. unsure.png
Advertisement
You never use the value of tempSprite, so it doesn't serve any real purpose. Just remove it from your code and restore a bit of sanity to the world. :)

You never use the value of tempSprite, so it doesn't serve any real purpose. Just remove it from your code and restore a bit of sanity to the world. smile.png


I thought so. Thank you, haha. I have been scratching my head for the last 3 hours asking myself what purpose did this serve?

:)

This topic is closed to new replies.

Advertisement