C++ – Run a function before initializing a class member
Comma operator to the rescue! An expression (a, b) will evaluate a first, then b. class DisplayOpenGL { public: DisplayOpenGL(HWND hwnd) : m_device(hwnd), m_opengl((m_device.SetPixelFormat(), m_device)) { }; private: DeviceContext m_device; OpenGLContext m_opengl; };