Hi,

I am having a problem trying to get a callback function to work within a class. Its from the DXUT Direct X source code example. I'm basicly trying to get a callback to call a function within a class. I'm stuck, been reading around looking at all these pointers to functions and I'm confused.

g_SampleUI.SetCallback( OnGUIEvent );

error C3867: 'SETTINGSPAGE::OnGUIEvent': function call missing argument list; use '&SETTINGSPAGE::OnGUIEvent' to create a pointer to member

Now the function is from DXUT and it wants.. PCALLBACKDXUTGUIEVENT pCallback

It worked fine with just g_SampleUI.SetCallback( OnGUIEvent ) outside of a class. This is where I fail with pointers, damn confusing things.
Oh and OnGUIEvent is defined in the same class.

you can not make non-static class methods callback functions. Make the method static and it should work.

I tried putting it as static but get the following compile error.


g_SampleUI.GetStatic( IDC_OUTPUT )->SetText( wszOutput );
left of '.GetStatic' must have class/struct/union

Is this because its now static? g_SampleUI is used fine elsewhere?

Static methods are called like this:

UIClass::GetStatic( IDC_OUTPUT )->SetText( wszOutput );

Replace UIClass with the name of the class for g_SampleUI.

I get

illegal call of non-static member function

with CDXUTDialog::GetStatic, is this because a static function must call another static function?

static methods can not call or use non-static methods/data. static methods behave more like non-class functions, which also can not directly access class objects.

Please post more code, or an example that has the same problem. Something is wrong, but playing 20 questions will take a while. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.