C++ Class, pointer and initialization help needed?

Ok so ive got a class called Imagehandler, this has a few functions, the main 2 giving me trouble are the "loadSprite" function and the "createBuffer" function. The loadSprite(BITMAP* x, const char* Filename, takes those parameters, the create buffer take the parameters createBuffer(BITMAP* x, int Screenwidth, int Screenheight). I create 2 bitmaps like this for the "BITMAP x" parameter :
BITMAP* Buffer;
BITMAP* Player;
I use them in the functions, yet it tells me they are not intialized? how am i supposed to initialize them? also inside the functions they both are set to something "Initialized" as its put, like the Buffer is this :
x(Which is the Buffer) = create_bitmap(int Screenwidth, int Screenheight) and its pretty much the same for the Player bitmap. How do i stop getting theese warning telling me to initialize the bitmaps? btw my error code is c4700 - uninitialized local varibal '(variable name) ' Used.
Any help would be amazing, thanks!
Last edited on
Instead of BITMAP*, try just BITMAP, but send the address to the function like so:

&Buffer, &Player
Or if you really must allocate the BITMAP objects on the heap, then somthing like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class BITMAP
{
public:
	BITMAP();
	~BITMAP();
};

BITMAP::BITMAP()
{
}

BITMAP::~BITMAP()
{
}

class Imagehandler
{
public:
	Imagehandler();
	~Imagehandler();

	void loadSprite(BITMAP** x, const char* Filename);
	void createBuffer(BITMAP** x, int Screenwidth, int Screenheight);	
};

Imagehandler::Imagehandler()
{
}

Imagehandler::~Imagehandler()
{
}

void Imagehandler::loadSprite(BITMAP** x, const char* Filename)
{
	*x = new BITMAP();	// allocate BITMAP on the heap at address specified at: *x
}

void Imagehandler::createBuffer(BITMAP** x, int Screenwidth, int Screenheight)
{
	*x = new BITMAP();	// allocate BITMAP on the heap at address specified at: *x
}



int main()
{
	Imagehandler Handler;							// handler on the stack
	BITMAP* Buffer(NULL), *Player(NULL);		// we are creating BITMAP's on the heap:

	// create BITMAP's on the heap:
	Handler.createBuffer(&Buffer, 200, 300);






	// to do - delete any memory allocated on the heap:
	if (Buffer)
		delete Buffer;
	if (Player)
		delete Player;

	return 0;
}
Topic archived. No new replies allowed.