Advertisement

local pointers to objects

Started by May 27, 2002 02:12 PM
3 comments, last by Laroche 22 years, 5 months ago
I have a class called CDDW (class direct draw wrapper) and i want to initialize it in a global function called Initialize_DirectDraw()..Now the problem is, if i initialize it like this:
  
int Initialize_DirectDraw(HWND hWnd, HINSTANCE hInstance)
{
CDDW *pDirectDraw = new CDDW(hWnd);
return (TRUE);
}
  
then im getting a memory leak..I want the cpp files dealing with graphics and the ones on initialization and closing to have access to the pointer...how would i go about making the pointer global? Or am i doing something entirely wrong? EDIT: fixing tags [edited by - laroche on May 27, 2002 3:13:16 PM]
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Are you calling delete on pDirectDraw after you finish with it? If not that''s probably the problem.

delete pdirectDraw;

is how you would do that.
Advertisement
But if i delete it in the function how would i use it in the other .CPP files in the rest of my program?
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Instead of a function calling Initialize_DirectDraw, it could simply create a new CDDW;. The pointer could be passed to the functions / classes that need it, and can be deleted once you''re finished with it.
Hmm, thats a much more simple and efficient answer to my dilemna then I thought. Thanks alot!
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content

This topic is closed to new replies.

Advertisement