Archived

This topic is now archived and is closed to further replies.

Structural

error trying to make a window class

Recommended Posts

Structural    328
I have finally decided to get on with the show and make a window class to create and manage my device and rendering contexts. Only thing is that I''m getting an error I don''t understand: error C2252: ''hWnd'' : pure specifier can only be specified for functions I get these errors for my window handle, my device context and rendering context. The program instance works fine. I don''t quite understand this.
class COpenGLWindow
{
	HGLRC           hRC=NULL;							// Permanent Rendering Context
	HDC             hDC=NULL;							// Private GDI Device Context
	HWND            hWnd=NULL;							// Holds Our Window Handle
	HINSTANCE       hInstance;							// Holds The Instance Of The Application
};
 
______________________________ "A computer is meant to be a big calculator, not a storage device" Struct.m33p.net

Share this post


Link to post
Share on other sites
SysOp_1101    122
You can''t directly assign a value to member variables in a class declaration. You need to use the constructor if you want to initialize your variables to NULL (or any other value) when an instance of the class is created.

Try this:


  
class COpenGLWindow{
public:
COpenGLWindow();
private:
HGLRC hRC;
HDC hDC;
HWND hWnd;
HINSTANCE hInstance;
};

COpenGLWindow::COpenGLWindow():hRC(NULL), hDC(NULL), hWnd(NULL), hInstance(NULL) {
//Other initialization code goes here

}


HTH

SysOp_1101

Share this post


Link to post
Share on other sites
Thunder_Hawk    314
Try this:

  
class COpenGLWindow
{
public:
COpenGLWindow () : hRC(NULL), hDC(NULL), hWnd(NULL) {}
HGLRC hRC;
HDC hDC;
HWND hWnd;
HINSTANCE hInstance;
}

The stuff after the colon there represent an initializer list, setting each of those variables to NULL when an instance is created. You can only do this on the constructor. It could have also been written:

  
class COpenGLWindow
{
public:
COpenGLWindow () {
hRC = NULL;
hDC = NULL;
hWnd = NULL;
}
HGLRC hRC;
HDC hDC;
HWND hWnd;
HINSTANCE hInstance;
}


It''s generally more effecient to use the initializer list method though. The two can be combined of course. If you need other forms of initialization than simple default values you''ll have to put them in the constructor itself.

______________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________

Share this post


Link to post
Share on other sites
petewood    819
Classes and structures in c++ are declared with variables and functions. Then in the constructor you can initialise the values. You can't do it in the definition like you're doing.

The message you're getting is to do with the fact that you can declare virtual functions = 0; which means they have to be overidden in derived classes. They're called 'pure virtual' functions, not important to your problem.

      
class COpenGlWindow {
HGLRC hRenderingContext;
HDC hDeviceContext;
HWND hWindow;
HINSTANCE hApp;
public:
COpenGlWindow(HINSTANCE app): HGLRC(0), HDC(0), HWND(0), HINSTANCE(app) {};
~COpenGlWindow() {};
};


normally I'd put the functions in a seperate cpp file but I've put it all together to be brief.

[edited by - petewood on January 30, 2003 2:56:22 PM]

Share this post


Link to post
Share on other sites