Issues with structs and Classes

Started by
2 comments, last by MARS_999 21 years, 11 months ago
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]
Advertisement
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!
myTGA is a pointer. In the constructor you use it without initializing it.
jobless beat me to it.

Get rid of the pointer notation, and use . instead of ->
daerid@gmail.com

This topic is closed to new replies.

Advertisement