Array of classes

Started by
12 comments, last by theObserver 20 years, 7 months ago
BOOL cSprite::Create(cGraphics2d * GraphicSource,LPDIRECTDRAWSURFACE7 SSurface,int Index,int Timer,int X,int Y)
{
if (!(Graphics == GraphicSource))
return false;

This code before is in the Create function of cSprite. Unless your setting cSprite.Graphics to something prior to this (which is doubtful as this is the create method) then it will have either a garbage value in it if you didnt initialize it properlly or NULL(0) value if you did.

Example:

cSprite()::cSprite()
{
Graphics = NULL;
}

if thats somewhere before create then ou should have a zero value there, and thus dont need/should be doing that test at all.

~ Chris
Advertisement
its:
Graphics = GraphicSource

because I need to store the pointer to a graphic class. The if statement is just to make sure that GraphicSource is not null.

The problem is (I think) that cSprite::Create is getting called from a pointer that doesnt actually point to anything but garbage so the graphics pointer doesnt actully exit. When I put a watch on graphics its value is ??????.

I can take that line out and it would just crash on the next line.

Also I if I were to do this

Map[1].Sprite = NULL;
The value stored in Map[1].Sprite also remains unchanged. And for another strange reason Map[0].Sprite->Create doesnt crash but every index higher than zero (map[2],map[10]) does. But even with Map[0] I still cant change the value of Map[0].Sprite->Sprite. It seems that they are already memory allocated to it.

It doesnt make any sence!!!!!!!!

[edited by - theObserver on September 1, 2003 9:45:13 PM]
Oh Duh. lol sorry i didnt even see that and i thought programmers get smarter with age? lol

Umm. No that really doesnt make any sence lol. Basically i dont know how to help without picking through code myself. If you want you can post it(if its small) or you can email/icq/aim it to me and ill figure out whats wrong, and explain it for you.

~ Chris
Got it!

Inspiration came with my morning cup of coffee and bowl of Fruit and Fiber.

Map is already a predefinded class in MFC. So I changed

cCreature Map[MAPSIZE];
to
cCreature TheMap[MAPSIZE];

and everything is working fine. I would have thought the stupid compiler would have kicked up an error over Map already being defined. Only took me two weeks to figure it out. *hangs head in shame*

But thanks for all you help. I appreciate it

This topic is closed to new replies.

Advertisement