C/C++ tip

Started by
10 comments, last by Amadrias 22 years, 4 months ago
hi all, I''d like to submit a class method to LS_RegisterHUDFunction this way : void HANDLERCLASS::SetRenderFunction() { LS_RegisterHUDFunction(myclass.HUDRender); } it do not work correctly as my compiler says when I try to build : error C2664: ''SetRenderFunction'' : cannot convert parameter 1 from ''void'' to ''void (__cdecl *)(void)'' Expressions of type void cannot be converted to other types ANy tip on how to do that using C++ and is there a performance cost ? Thanks, Amadrias
Advertisement
It''s got to be a static member function of your class. Define it as:

static void __cdecl HUDRender(void);

No performance cost (as far as I know), but you can''t overload the function or have multiple instances of it because it''s static.
thx Dr Pain...
Now I still have another problem.

In that static method, I do have 2 calls to :

PR_TransformEntity(m_pEntity);
PR_RenderEntity(m_pEntity);

where m_pEntity is defined in the current class.

The compiler says I can't use sdata members in a static function...

please help...

Amadrias

PS : Did you get my email in hotmail ?

Edited by - amadrias on December 17, 2001 11:41:43 AM
That's right.
You can't use the variables that are object specific, in a static function.

You're only options are:
1) Make the class a regular non-static class function.
2) Pass in the variables as parameters.

Edited by - Gorky on December 17, 2001 12:04:59 PM
Gorky is correct, you can''t access members from the static function, because it''s technically not a member of the class. Or perhaps I should say it''s not a member of the instance of that class.

What you could do is have a public member function that returns the variable you want access to, for instance:

Entity * GetEntity(void) { return m_pEntity; }

Then you''ll also need access to the instance of the class within your static function. If it''s a global, just define it as extern within the function. Then you can retrieve the member variable as:

myClass->GetEntity()


And no, I didn''t get your email. Perhaps hotmail is running slow?
Thanks guys,

This just gives me the feeling I was getting with PR. Even if it is the best, in my own opinion, Graphics Engine available for indy developers, Chris should willing to get his next version more object oriented and more open minded.

The only way I can get it throught is by doing my own High level engine. I am, and I think I am not the only one, always trying to get some tricky code placed in some globals so I can have the things running properly using an Object Oriented Programing view.

Chris, if you could get us updated with what are your thoughts on that point, it would help a lot.

Thanks anyway to DrPain and Gorky for their helpful tips.

Amadrias
I don''t see myself changing the entire API over to C++ and rewriting all of the documentation in the future, unless I run out of other ideas and have a couple of years of spare time.


Author of Power Render (http:/www.powerrender.com)
You mean you have a life, Chris?

-Rich
I didn''t mean to get you within that huge work Chris.

I just wanted to tell that you should maybe think on getting some of the new things you will be doing more OOP ?...

I completely understand the amount of work you made until getting where PR is and the no-one man thing that would be considering porting the overall PR engine to C++.

Amadrias
C isn''t an object oriented programming language, so I can''t add OOP stuff unless I switch. So basically you''re asking me to learn/use another language and that isn''t going to happen quickly.

Author of Power Render (http:/www.powerrender.com)

This topic is closed to new replies.

Advertisement