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    | 
		 
		
			
				
				
				  | 
					
						  
						mirek
						 Messages: 14271 Registered: November 2005 
						
					 | 
					Ultimate Member  | 
					 | 
		 
		 
	 | 
 
	
		rafiwui wrote on Mon, 03 July 2017 16:15I 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: 
  
 
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
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
  
 
Goto Forum:
 
 Current Time: Tue Nov 04 16:55:05 CET 2025 
 Total time taken to generate the page: 0.05636 seconds 
 |