   need help about Beginning Game Programming
  I bought Beginning Game Programming, and follow the examples. In Chapter 4, there's something I can't understand. To read .bmp files, we use bitmap class, but the line Quote: : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0) in the following code is strange to me. Who can tell me what this means? Bitmap::Bitmap()  : m_hBitmap(NULL), m_iWidth(0), m_iHeight(0){}Thanks for any feedback.   
  That is the initializer list.  It fills the corresponding variables, or passes values to constructors from inherited objects, when you invoke the constructor, but happens before execution reaches the code inside the constructor.   ;  m_hBitmap(NULL) is like saying m_hBitmap = NULL;   ;Quote:Original post by DaishimThat is the initializer list.  It fills the corresponding variables, or passes values to constructors from inherited objects, when you invoke the constructor, but happens before execution reaches the code inside the constructor.Thanks for your help.It still puzzles me. The use of ":" here is new to me. I know that when we want to inherit a base class we use ":", but here, I never see it. I can't find in my C++ books.  Can you explain it more or just tell me where to find this?Thanks.   ;  Ok, for example lets say we have a class like this:Header:class Bitmap{   private:int Width;int Height;unsigned char *Pixels;   public:Bitmap(int New_Width, int New_Height, unsigned char *New_Pixels);~Bitmap(void);};Source:Bitmap::Bitmap(int New_Width, int New_Height, unsigned char *New_Pixels) : Width(New_Width), Height(New_Height), Pixels(New_Pixels){// Empty}Bitmap::~Bitmap(void){if(Pixels)delete Pixels;}The code:Bitmap::Bitmap(int New_Width, int New_Height, unsigned char *New_Pixels) : Width(New_Width), Height(New_Height), Pixels(New_Pixels){// Empty}Is equivilant to:Bitmap::Bitmap(int New_Width, int New_Height, unsigned char *New_Pixels){Width = New_Width;Height = New_Height;Pixels = New_Pixels;}With the small exception that the initializer list is executed before anything in the constructor is executed.  For example...Bitmap::Bitmap(int New_Width, int New_Height, unsigned char *New_Pixels) : Width(New_Width), Height(New_Height), Pixels(New_Pixels){// If pointer is valid, change first pixel to white (assuming 24bit image)if(Pixels){Pixels[0] = 255;Pixels[1] = 255;Pixels[2] = 255;}}So, Width, Height, and Pixels are initialized to their respective values before the constructor code executes.  You can put constant values into an initializer list, as demonstrated in your initial post instead of using the constructors arguments.Hope that helps to clear things up a bit.   ;  That makes sense. I got it. Thanks.   ;  That code is not completely equivalent, apart from the earlier initialization. Without such specific initialization, all those objects would be initialized with their default values, and then assigned a value, inside the constructors body.// So, what happens when you write the following code:Bitmap::Bitmap(int New_Width, int New_Height, unsigned char *New_Pixels){Width = New_Width;Height = New_Height;Pixels = New_Pixels;}// is essentially this:Bitmap::Bitmap(int New_Width, int New_Height, unsigned char *New_Pixels) : Width(), Height(), Pixels(){Width = New_Width;Height = New_Height;Pixels = New_Pixels;}In other words, directly initializing objects with the values you intended them to have is more efficient than assigning them the values, as in that case the default initialization is a waste of time.   