I need syntax help!

// What do the following code snippets do?

::TranslateMessage( &msg );

/* It seems to be a class method. It's in a class definition. Why the double colon? What does it do? */


VisualizeWin32() : m_hBitmap(0), m_hdcMem(0), m_bInitialized(0), m_szMessage(0)

/* And the second snippet. Also in a class definition. What is the colon after the method beginning do? Those after it are all data members. */


method(parameters) = 0;
// I have also seen this multiple times, what IS this?
Last edited on
closed account (o3hC5Di1)
Hi there,

::TranslateMessage( &msg );

http://stackoverflow.com/questions/4269034/what-is-the-meaning-of-prepended-double-colon-to-class-name
That topic explains it well

VisualizeWin32() : m_hBitmap(0), m_hdcMem(0), m_bInitialized(0), m_szMessage(0)

The part after the single colon is called an initialization list. They allow you to set values for members even before the constructor is called. For more explanations:
http://stackoverflow.com/questions/4589237/c-initialization-lists

virtual method(parameters) = 0;

This declares a pure virtual function, as opposed to a regular virtual function. Pure virtual functions are declared in base classes. Their effect is that every child class is required to implement this function. It can choose the implementation, but it has to be defined. This gives you a way to define a contract between a base and a child class, saying "you can only derive from me if you implement this function".

Hope that helps.

All the best,
NwN
Thank you VERY much! :)
Last edited on
Topic archived. No new replies allowed.