Error while using connect function in class

  • 2 Replies
  • 55 Views
Error while using connect function in class
« on: 28 April 2020, 17:36:26 »
Hello,

When I used connect in int main(), it worked fine, but after moving it to the class it doesn't work anymore.

The code won't compile and these error messages show up:
error C3867: 'PixelPaint::onExitClicked': non-standard syntax; use '&' to create a pointer to member
error C2672: 'tgui::SignalWidgetBase::connect': no matching overloaded function found

Code:

Code: [Select]
menu->connect("MenuItemClicked", onExitClicked, std::ref(window));
Code: [Select]
void onExitClicked(sf::RenderWindow& window, const std::string& item)
{
if (item == "Wyjscie") {
window.close();
}
}
« Last Edit: 28 April 2020, 17:41:34 by JerryBohenek »

*

texus

  • *****
  • 1539
    • View Profile
    • Texus's Blog
Re: Error while using connect function
« Reply #1 on: 28 April 2020, 17:41:29 »
Class member functions aren't the same as free functions, they have an extra hidden "this" pointer that you also need to bind.

If "onExitClicked" is part of the PixelPaint class then the connect function should look like this:
menu->connect("MenuItemClicked", &PixelPaint::onExitClicked, this, std::ref(window));

Note that the "this" in the above code is only correct when this line of code is also placed inside the PixelPaint class. If the code is called from somewhere else the instead of "this" you should just pass the address of the PixelPaint object from which you want onExitClicked to be called.

Re: Error while using connect function in class
« Reply #2 on: 28 April 2020, 17:48:59 »
Oh, that's right,

Thanks a lot and stay safe!  :D