Inheritance and CINT

I have a class called TZMdiFrame that inherits TGMdiFrame.

[code]class TZMdiFrame : public TGMdiFrame {
private:

public:
TZMdiFrame (const TGMdiMainFrame *mainFrame, Int_t w, Int_t h, UInt_t options = 0) {
TGMdiFrame(mainFrame, w,h,options);

} [/code]

The code below that uses the original TGMdiFrame class works fine::

TGMdiFrame *mdiFrame; mdiFrame = new TGMdiFrame(this->fMain, 900, 600, kHorizontalFrame); mdiFrame->SetWindowName("New Window");

The code below that uses the inherited class does not work:

TZMdiFrame *mdiFrame; mdiFrame = new TZMdiFrame(this->fMain, 900, 600, kHorizontalFrame); mdiframe->SetWindowName("New Window");

I am running this in CINT. The error message that I get is:

It points to the third line in the above code .

Please let me know if I should be doing anything in the code to make my inherited class work.

Thanks.

Hi,

First of all, please correct you constructor:[code]
class TZMdiFrame : public TGMdiFrame {
private:

public:
TZMdiFrame (const TGMdiMainFrame *mainFrame, Int_t w, Int_t h, UInt_t options = 0) : TGMdiFrame(mainFrame, w, h, options) {}
};[/code]
Then, to verify your code, please use ACLiC: .x yourmacro.C+Note the + after the name of your macro.
Then, if it still doesn’t work, please post a running macro showing the problem.

Cheers,
Bertrand.

Hi,

Due the way C++ implements inheritance (virtual table), you must compile any class that inherits from a compiled class. Is TZMdiFrame compiled or interpreted?

Cheers,
Philippe.

TZMdiFrame was an interpreted class. In order for inheritance to work, I tried to compile the entire code using ACLiC. The compilation and linking worked with no errors. But, I got the following messages that is unrelated to the original problem:

Both CloseWindow() and HandleMenu(int) methods do exist in the code and they work fine when run in interpretive mode.

Any help will be very much appreciated.

Hi,

In order to use signals/slots, you have to generate dictionary for your class. e.g.:[code]class TZMdiFrame : public TGMdiFrame {

public:

ClassDef(TZMdiFrame, 0)
};

// generate dictionary for TZMdiFrame
#ifdef MAKECINT
#pragma link C++ class TZMdiFrame+;
#endif[/code]
Cheers, Bertrand.

Thanks for pointing me in the right direction. I added the ClassDef and pragma statements and tried to compile. Here is the error message I am getting:

I am attaching a tar file containing all the program modules.

As again, any help will be much appreciated.
CAS.tar.gz (4.18 KB)

Hi,

You must inherit publicly:class TZMdiFrame : public TGMdiFrame{

Cheers,
Philippe.

I changed it to “public” and the compilation works. I am now back to the original problem as seen in this message :

Thanks in advance for your help.

Hi,

  1. in TZMainFrame.cpp, please keep:

#ifdef __MAKECINT__ #pragma link C++ class TZMdiFrame+; #endif
2) in TZMdiFrame.h, move these methods to public, as shown below:

public: void HandleTreeDoubleClicked(TGListTreeItem* entry, Int_t btn, Int_t x, Int_t y); void HandleTreeClicked(TGListTreeItem* entry, Int_t btn, Int_t x, Int_t y);
3) in TZMainFrame.h, move these methods to public, as shown below:

public: void CloseWindow(); void AddNewMdiFrame(); void CreateMenuFile(); void CreateMenuEdit(); void CreateMenuView(); void CreateMenuTools(); void CreateMenuWindow(); void CreateMenuHelp(); void EnableDisableMenus(); void NewMenuItemActionPerformed(); void OpenMenuItemActionPerformed(); void CloseMenuItemActionPerformed(); void SaveMenuItemActionPerformed(); void SaveAsMenuItemActionPerformed(); void PrintMenuItemActionPerformed(); void PrintSetupMenuItemActionPerformed(); void ExitMenuItemActionPerformed(); void HandleMenu(Int_t id);
The slot methods have to be public.

Cheers,
Bertrand.

Dear Bertrand, Philippe,
Thanks a lot for all your help. Everything works perfectly after I made all your suggested changes. :smiley:

Cheers