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 #48460 is a reply to message #48426] Wed, 05 July 2017 14:07 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
rafiwui wrote on Mon, 03 July 2017 16:15
I had an interesting issue with a MenuBar and a THISBACK.
I made three classes: MenuBarWindow, FnWindow and MyWindow.
- MenuBarWindow only has the MenuBar attribute and the method I want as its callback.
- FnWindow inherits from MenuBarWindow and has some buttons for the F1-F8 keys and the corresponding callback methods.
- MyWindow inherits from FnWindow and is the main window in my application.

Here is an example code:
class MenuBarWindow : public TopWindow
{
protected:
    MenuBar m_menuBar;
    
public:
    typedef MenuBarWindow CLASSNAME;
    MenuBarWindow(int _sizeX, int _sizeY);

protected:
    virtual void MenuBarMain(Bar& _bar) = 0;
};

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));
}


class FnWindow : public MenuBarWIndow
{
protected:
    Button b_fn1;
    // ...
    Button b_fn8;

public:
    typedef FnWindow CLASSNAME;
    FnWindow(int _sizeX, int _sizeY);

private:
    virtual void OnClickFn1() = 0;
    // ...
    virtual void OnClickFn8() = 0;
};

FnWindow::FnWindow(int _sizeX, int _sizeY)
    : MenuBarWindow(_sizeX, _sizeY)
{
    // Adding buttons here...

    b_fn1 <<= THISBACK(OnClickFn1);
    // ...
    b_fn8 <<= THISBACK(OnClickFn8);
}

// MyWindow header...
MyWindow::MyWindow(int _sizeX, int _sizeY)
    : FnWindow(_sizeX, _sizeY)
{
    // do sth...
}

In the MyWindow files are declarations and definitions for the virtual methods.

If I run this the program stops and shows me this and exits the application when you continue:
index.php?t=getfile&id=5328&private=0

If I remove
virtual void MenuBarMain(Bar& _bar) = 0;
and move
m_menuBar.Set(THISBACK(MenuBarMain));
from MenuBarWindow to MyWindow everything works fine.

At first I thought this is because the method is pure virtual and needs an implementation in the class from where I call it or use THISBACK but then I should get this strange behaviour after my changes as well because I do the same with the button callbacks but they work perfectly.

So does anyone has an idea why this is happening? Is this a generell C++ thing or is it a U++ thing?


I see nothing wrong. Please, as this really looks like a small package experiment, follow the suggestion and compress the whole package and attach it to the post so that we can test it quickly.

Mirek
 
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: Sat Apr 27 23:37:44 CEST 2024

Total time taken to generate the page: 2.97542 seconds