Subscribing Events with Inherited classes

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Kevin
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon May 26, 2008 15:44

Subscribing Events with Inherited classes

Postby Kevin » Fri Sep 05, 2008 00:22

Hello,

I have a class NurikabeGUI, which inherits from BoardGUI. Inside BoardGUI I have the function:

Code: Select all

bool BoardGUI::checkClicked(const CEGUI::EventArgs& args)
{
    ...
    return true;
}

I am trying to subscribe a button to this callback in the NurikabeGUI constructor. I first tried:

Code: Select all

_checkButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&BoardGUI::checkClicked, this));

which gives me the errors:

Code: Select all

c:\Progs\PencilPuzzles\NurikabeGUI.cpp(24): error C2248: 'Penpa::BoardGUI::checkClicked' : cannot access protected member declared in class 'Penpa::BoardGUI'

Code: Select all

c:\Progs\PencilPuzzles\NurikabeGUI.cpp(24): error C2661: 'CEGUI::SubscriberSlot::SubscriberSlot' : no overloaded function takes 2 arguments

I then tried

Code: Select all

_checkButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&NurikabeGUI::checkClicked, this));

since 'this' is an instance of NurikabeGUI. In this case, I get the second error as above, but not the first.

So I suppose my question is this: Is it possible to use an inherited function as a callback?

Thanks in advance!
Kevin

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Subscribing Events with Inherited classes

Postby Jamarr » Fri Sep 05, 2008 16:01

Kevin wrote:So I suppose my question is this: Is it possible to use an inherited function as a callback?

Yes, of course.

Code: Select all

c:\Progs\PencilPuzzles\NurikabeGUI.cpp(24): error C2661: 'CEGUI::SubscriberSlot::SubscriberSlot' : no overloaded function takes 2 arguments

This means your code is not written correctly. You probably messed up the decleration or something. If you search the forum for "no overloaded function takes arguments" (note I left out the '2' - it messes up the results page) every single one of those posts end up being syntax related.

User avatar
Kevin
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon May 26, 2008 15:44

Postby Kevin » Fri Sep 05, 2008 19:35

Hello,

Thanks for the reply, but I don't think that is the problem. I have successfully subscribed to many events before with no problems. The difference with this one is that the function I am trying to subscribe to is not declared in the class itself, but a class it inherits from, which seems to be what it's complaining about.

Kevin

User avatar
Kevin
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon May 26, 2008 15:44

Postby Kevin » Sun Sep 07, 2008 20:04

Just an update:

I tried cut-and-pasting the function exactly as it was from the base class (BoardGUI) to the derived class (NurikabeGUI), and now it works fine, so the problem is definitely to do with the fact that it's an inherited function.

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Postby Jamarr » Wed Sep 10, 2008 18:37

Yes, I see. I missread your initial post. I thought you had already redefined the method in the derived class.

It is odd, because the CEGUI::SubscriberSlot class already has a templated constructor for class methods. For some reason the compiler is not recognizing inherited class methods as valid template parameters for that constructor.

You can still work around the issue by explicitly using the FunctorReference constructor instead, like so:

Code: Select all

_checkButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(CEGUI::MemberFunctionSlot<NurikabeGUI>(&NurikabeGUI::checkClicked, this)));


Return to “Help”

Who is online

Users browsing this forum: No registered users and 17 guests