Sign in to follow this  

Pointer to an array of base characters?

This topic is 1971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. [img]http://public.gamedev.net//public/style_emoticons/default/unsure.png[/img]

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1343278803' post='4963182']
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. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]

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

:)

Share this post


Link to post
Share on other sites

This topic is 1971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this