Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Callbacks and Timers » THISBACK and inheritance
Re: THISBACK and inheritance [message #48481 is a reply to message #48475] Thu, 06 July 2017 20:25 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1093
Registered: August 2007
Senior Contributor
Hello,

It is a "C++ thing." Smile
As far as I can see, you are calling a pure virtual method (or storing its address -which is undefined at that moment) from base constructor.
Calling a pure virtual method from base constructor is undefined behaviour. (Since at that point the vtable entry for the said method is not yet assigned. It is basically "0" (undefined)). That's why you dont't even get an explicit error message.

MenuBarWindow::MenuBarWindow(int _sizeX, int _sizeY)
{
    SetRect(0, 0, Zx(_sizeX), Zy(_sizeY + m_menuBar.GetStdHeight(m_menuBar.GetFont())));
    AddFrame(m_menuBar);
    m_menuBar.Set(THISBACK(MenuBarMain)); // <-- Undefined behaviour.
}


Why did you define a menu handler virtual anyway? We are using callbacks to define menus, so you won't really need virtual functions for this purpose.
if you want to store m_menuBar member in MenuBarWindow class that's fine, but since it is a protected member, it can be accessed from the derived classes:

MyWindow::MyWindow(int _sizeX, int _sizeY)
    : FnWindow(_sizeX, _sizeY)
{
        AddFrame(m_menuBar);                             // This should
	m_menuBar.Set(THISBACK(MenuBarMain));            // work.
}


Also I see that you use some obscure internal macro(s) explicitly. You dont need them at all.

Best regards,
Oblivion



[Updated on: Thu, 06 July 2017 21:07]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: About storing references and pointers to callbacks.
Next Topic: [REQUEST]: Allow callback() template to work also with non-void and non-bool return types.
Goto Forum:
  


Current Time: Sun Apr 28 20:23:32 CEST 2024

Total time taken to generate the page: 0.02640 seconds