error trying to make a window class

Started by
5 comments, last by Structural 21 years, 2 months ago
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
STOP THE PLANET!! I WANT TO GET OFF!!
Advertisement
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
SysOp_1101
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 -- ¦þ
______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
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]
Oh shoddy!!

My bad, my bad...

I should look before I copy-paste between files the next time.
STOP THE PLANET!! I WANT TO GET OFF!!
Could you post your final class? I''d be interested in seeing how you implement this.

Thanks
---------------------http://www.stodge.net
If you give me a day or so I''ll probably be done with it. If I remember this thread, I will (you could also drop me line tomorrow to remember me)
STOP THE PLANET!! I WANT TO GET OFF!!

This topic is closed to new replies.

Advertisement