Archived

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

MARS_999

Issues with structs and Classes

Recommended Posts

MARS_999    1627
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
{
public:
	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;
	}*myTGA;

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

#endif
  
now for my sprite.cpp file
  

Sprite::Sprite()
{
	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
Oluseyi    2103
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