Jump to content
  • Advertisement

Archived

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

kaepteniglo

Put NeHe's Tutorial in a Class

This topic is 5665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i''ve wanted to try to generate my own openGL Class with the functions from the tutorial. all works fine but the LRESULT CALLBACK WnDProc - Function will not work in my Class. When I trie to acces the WndProc function in CreateGLWindow() at the point: wc.lpfnWndProc = (WNDPROC) WndProc; I get an error: error C2440: ''type casT'' : '''' couldn''t be transfered in ''long (__stdcall *)(struct HWND__ *,unsigned int, unsigned int, long) Why do I get this error? How to fix it? kaepteniglo

Share this post


Link to post
Share on other sites
Advertisement
No, thx.

But now I got a lot of errors while compiling.

In the new CALLBACK WndProc-Function:

For example

illegal reference to a dataelement ''COGL::active'' in a static member function.

COGL is my Class-Name and active is one of the variables used by NeHe''s Tut.

kaepteniglo

Share this post


Link to post
Share on other sites
http://www.mvps.org/windev/cpp/class.html

An explanation on why it doesn''t work. I had a better link but I''ve lost it.

Afaik there are two ways to solve the problem. One of them is what Crispy suggested and involves making the callback static. The problem is that a static member fuction is not bound to a specific object and thus does not have a ''this'' pointer. That''s why you get the new error. The link above explains (in short) how to solve it. Another solution involves making the callback a friend of your class instead of making it part of it.

Share this post


Link to post
Share on other sites
Hey no problem. And another thing. As I''m sure you''ve discovered by now, the search function is down (Just noticed).

Share this post


Link to post
Share on other sites
www.gamedev.net has a tutorial where they do this.

http://www.gamedev.net/reference/programming/features/win32wrapper/page2.asp

Share this post


Link to post
Share on other sites
quote:
Original post by kaepteniglo
No, thx.

But now I got a lot of errors while compiling.

In the new CALLBACK WndProc-Function:

For example

illegal reference to a dataelement ''COGL::active'' in a static member function.

COGL is my Class-Name and active is one of the variables used by NeHe''s Tut.

kaepteniglo


is active a public or private variable.
If its private, then you can''t access it outside your class.
Only the functions inside your class can access it.
Either make it public or make a public function GetActiveVariable() that returns the value of active.

Share this post


Link to post
Share on other sites
quote:

is active a public or private variable.
If its private, then you can''t access it outside your class.
Only the functions inside your class can access it.
Either make it public or make a public function GetActiveVariable() that returns the value of active.




ah, no

the reason you get:

illegal reference to a dataelement ''COGL::active'' in a static member function.

is because the member is just that, a member of an instance of a class. A static function is basically the same as a C function in that you can call it anywhere without an actual object to call from
eg:

COGL::staticFunctionName();

would be fine anywhere, instead of:

COGL ogl;
ogl.normalFunctionName();

This should make it pretty obvious that you can''t access a member of a class in a static function because the this pointer does not exist.
ie, you can call the function without ever actually making a COGL object... Hence how can the members of a COGL object possibly be accessed when non have been created?

it''s hard to discribe.

btw, don''t fix this by making the members static. You will just fall into a bigger and bigger hole if you do that, not understanding the meaning of what your doing. (You also have to declare static members outside of a class declaration so their initial values can be set, which will lead to more compiler errors if you don''t know what your doing)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!