Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [TGUI] Why can't I pass a void* function pointer to tgui__button.connect?  (Read 3282 times)

0 Members and 1 Guest are viewing this topic.

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
(Note, this is a TGUI / C++ question, not sure if this is where I should post it.)

I'm trying to do this :


void GUIManager::CreateButton(std::string m_identifier, std::string m_buttonText, std::string m_fontPath, void* func, float m_xPos, float m_yPos, float m_width, float m_height)
{
       
        tgui::Button::Ptr m__temp_btn = std::make_shared<tgui::Button>();

        m__temp_btn->setFont(m_fontPath);
        m__temp_btn->setText(m_buttonText);
        m__temp_btn->setPosition(m_xPos, m_yPos);
        m__temp_btn->setSize(m_width, m_height);

        _buttonList.insert(std::make_pair(m_identifier, m__temp_btn));

        _buttonList[m_identifier]->connect("pressed", func); // It's because of this func parameter I get the error,

        _gui.add(_buttonList[m_identifier]);

}

 

Which TGUi doesn't want me to since it gives me this error :

Error   C2893   Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'   
 

What am I doing wrong? :/

(I think this should be enough code to reproduce the error)

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: [TGUI] Why can't I pass a void* function pointer to tgui__button.connect?
« Reply #1 on: September 10, 2016, 04:34:38 pm »
In c++ you shouldn't use void* unless you know what you are doing. There is no way TGUI could know what 'func' is or how many parameters it would have. You should use an std::function to store the function, so the parameter would have to be std::function instead of void*.

The best place to ask questions about TGUI is on the TGUI forum (or any other way mentioned on the contact page) because then I will get notified about your question immediately.
TGUI: C++ SFML GUI

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: [TGUI] Why can't I pass a void* function pointer to tgui__button.connect?
« Reply #2 on: September 10, 2016, 04:46:36 pm »
Oh, okay.

The function has no parameters, so I replaced void* func in the parameter with :

std::function<void> func

But now I get these errors instead :
Error   C2027   use of undefined type 'std::_Get_function_impl<_Fty>'
and
Error   C2504   'type': base class undefined
ยจ

I guess this is completely unrelated to both SFML and TGUi, should I post this somewhere else instead?

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: [TGUI] Why can't I pass a void* function pointer to tgui__button.connect?
« Reply #3 on: September 10, 2016, 04:48:57 pm »
It should look like this:
std::function<void()> func

The void is the return type and between the brackets you can put the parameters (none in this case).
TGUI: C++ SFML GUI

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: [TGUI] Why can't I pass a void* function pointer to tgui__button.connect?
« Reply #4 on: September 10, 2016, 04:52:40 pm »
I should probably have read the std::function documentation thing before posting.
But that made it work! Thank you :)

 

anything