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.
pcanal
March 10, 2009, 8:04pm
3
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:
root [0] .x mainApp.cpp+
Info in TUnixSystem::ACLiC : creating shared library /home/ravi/CAS/./mainApp_cpp.so
In file included from /home/ravi/CAS/./mainApp_cpp_ACLiC_dict.h:33,
from /home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:16:
/home/ravi/CAS/./mainApp.cpp:5: warning: ignoring #pragma link C
/home/ravi/CAS/./mainApp.cpp:6: warning: ignoring #pragma link C
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx: In function ‘ROOT::TGenericClassInfo* ROOT::GenerateInitInstanceLocal(const TZMdiFrame*)’:
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:51: error: ‘TQObject’ is an inaccessible base of ‘TZMdiFrame’
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:51: error: ‘TQObject’ is an inaccessible base of ‘TZMdiFrame’
/home/ravi/root/include/TObject.h: In function ‘void ROOT::delete_TZMdiFrame(void*)’:
/home/ravi/root/include/TObject.h:160: error: ‘static void TObject::operator delete(void*)’ is inaccessible
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:191: error: within this context
/home/ravi/root/include/TObject.h: In function ‘void ROOT::deleteArray_TZMdiFrame(void*)’:
/home/ravi/root/include/TObject.h:161: error: ‘static void TObject::operator delete ’ is inaccessible
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:194: error: within this context
/home/ravi/root/include/TObject.h: In function ‘int G__mainApp_cpp_ACLiC_dict_2075_0_5(G__value*, const char*, G__param*, int)’:
/home/ravi/root/include/TObject.h:156: error: ‘static void* TObject::operator new(size_t)’ is inaccessible
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:289: error: within this context
/home/ravi/root/include/TObject.h:160: error: ‘static void TObject::operator delete(void*)’ is inaccessible
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:289: error: within this context
/home/ravi/root/include/TObject.h:158: error: ‘static void* TObject::operator new(size_t, void*)’ is inaccessible
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:293: error: within this context
/home/ravi/root/include/TObject.h:163: error: ‘static void TObject::operator delete(void*, void*)’ is inaccessible
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:293: error: within this context
/home/ravi/root/include/TObject.h: In function ‘int G__mainApp_cpp_ACLiC_dict_2075_0_18(G__value*, const char*, G__param*, int)’:
/home/ravi/root/include/TObject.h:161: error: ‘static void TObject::operator delete ’ is inaccessible
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:374: error: within this context
/home/ravi/root/include/TObject.h:160: error: ‘static void TObject::operator delete(void*)’ is inaccessible
/home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:384: error: within this context
g++: /home/ravi/CAS/./mainApp_cpp_ACLiC_dict.o: No such file or directory
Error in : Compilation failed!
Error: Function mainApp() is not defined in current scope :0:
*** Interpreter error recovered ***
root [1]
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)
pcanal
March 11, 2009, 9:42pm
7
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 :
root [0] .L TZMdiFrame.cpp+
Info in TUnixSystem::ACLiC : creating shared library /home/ravi/CAS/./TZMdiFrame_cpp.so
root [1] .L TZMainFrame.cpp+
Info in TUnixSystem::ACLiC : creating shared library /home/ravi/CAS/./TZMainFrame_cpp.so
root [2] .L mainApp.cpp+
Info in TUnixSystem::ACLiC : creating shared library /home/ravi/CAS/./mainApp_cpp.so
In file included from /home/ravi/CAS/./mainApp_cpp_ACLiC_dict.h:33,
from /home/ravi/CAS/./mainApp_cpp_ACLiC_dict.cxx:16:
/home/ravi/CAS/./mainApp.cpp:6: warning: ignoring #pragma link C
/home/ravi/CAS/./mainApp.cpp:7: warning: ignoring #pragma link C
Warning in TClassTable::Add : class TZMdiFrame already in TClassTable
Warning in TClassTable::Add : class TZMainFrame already in TClassTable
root [3] mainApp();
Error in TQObject::CheckConnectArgs : signal TZMainFrame::CloseWindow() does not exist
Error in TQObject::CheckConnectArgs : slot TZMainFrame::HandleMenu(int) does not exist
Error in TQObject::CheckConnectArgs : slot TZMainFrame::HandleMenu(int) does not exist
Error in TQObject::CheckConnectArgs : slot TZMainFrame::HandleMenu(int) does not exist
Error in TQObject::CheckConnectArgs : slot TZMainFrame::HandleMenu(int) does not exist
Error in TQObject::CheckConnectArgs : slot TZMainFrame::HandleMenu(int) does not exist
Error in TQObject::CheckConnectArgs : slot TZMainFrame::HandleMenu(int) does not exist
root [4]
Thanks in advance for your help.
Hi,
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.
Cheers