This topic is now archived and is closed to further replies.

Issues with structs and Classes

This topic is 5701 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

Is it possible to declare a struct inside a class? I seem to be having a crash issues since I declared a struct inside my class. Here is my code ...

#ifndef Sprite_H
#define Sprite_H

class Sprite
	int armor;
	int speed;
	char *weapon1;
	char *weapon2;
	char *weapon3;
	char *name;
	unsigned int textures[1];
	struct TGAFILE
	unsigned char imageTypeCode;
	short int     imageWidth;
    short int     imageHeight;
    unsigned char bitCount;
    unsigned char *imageData;

	void LoadTexture(void);
	void Draw(void);
	void Update(void);
	bool LoadTGAFile(char *filename, TGAFILE *tgaFile);

now for my sprite.cpp file

	armor = 0;
	speed = 0;
	weapon1 = "None";
	weapon2 = "None";
	weapon3 = "None";
	name = "None";
	myTGA->bitCount = ' ';
	myTGA->imageHeight = 0;
	myTGA->imageTypeCode = ' ';
	myTGA->imageWidth = 0;
not sure whats going on or the problem but am new to the whole class thing. Thanks Bill Gates is my Pool Boy!! Nothing is to good for me!! [edited by - Mars_999 on May 5, 2002 11:25:49 PM]

Share this post

Link to post
Share on other sites
Since TGAFILE is declared within the Sprite class, it is enclosed in that namespace. To refer to it outside the Sprite class and its methods, refer to it as Sprite::TGAFILE.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!

Share this post

Link to post
Share on other sites