Win32 / Classes / Default Constructor Issue

Started by
3 comments, last by Sanadan 20 years, 8 months ago
In the game I''m creating I''ve thought of a problem I am going to have to solve eventually and I''m not sure how I''m going to do it yet. The way I understand it, when you create an array of classes such as:
MyClass a[10]; 
or
MyClass *prt = new MyClass[10]; 
the default constructor is called 10 times, one for each instance of the class within the array. (Feel free to correct me if I''m wrong). So, this is where my problem arises, I am not sure how I could create a default constructor for my classes and I will need to do some type of array allocation eventually. Currently my constructor prototype would be:
MyClass(HWND hwnd, HDC backBuffer); 
So, as you would guess, I''m planning on passing the hwnd and back buffer to each instance of the class as I instantiate them, so that the class can perform it''s own drawing and such. All of this is done in WIN32. So anyone have any ideas how I can solve this? I''m worried that with a default constructor I have no way of sending the correct handle to my window and back buffer, which the classes need.
Advertisement
Create another method called MyClass::Init(HWND, HDC) and pass what you need to it after you create your class.


Qui fut tout, et qui ne fut rien
Invader''s Realm
That was what I thought of as well, but wasn''t sure if there was a cleaner way of doing it that I was missing. I was going to set them to NULL in my default constructor and then initialize post instantiation. For some reason this doesn''t sit extrememly well with me, since I like to have the constructor initialize everything.
Is there any reason I couldn''t declare the HWND and HDC variables of my class to be static? That way I would only need to initialize them once.
quote:Original post by Sanadan
Is there any reason I couldn''t declare the HWND and HDC variables of my class to be static? That way I would only need to initialize them once.


The only reason that comes to mind is if they ever need to not be the same for all classes, ie. if you are drawing to multiple windows or Display Contens... but for most games that seems unlikely



/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''''t use it...
/Please excuse my bad spelling - My native language is binary not english|Visit meTake my advice - I don''t use it...

This topic is closed to new replies.

Advertisement