Virtual inheritance support? EXC_BAD_ACCESS when trying...

From: Nicholas Devenish <misnomer_at_gmail.com>
Date: Tue, 20 Oct 2009 01:07:06 +0100


Dear Roottalk,

I have been implementing a class structure, that uses multiple inheritance for interfaces - needing virtual inheritance. This all works perfectly in compiled code, but it turns out that if I try to downcast a pointer from a ROOT macro, and then try to access one of the virtual functions, I get a EXC_BAD_ACCESS failure. I read that dynamic_cast is not well supported in CINT (albeit from a 10 year old roottalk thread), but would like to know if it is something I am doing wrong or an actual CINT limitation that I can try to work around.

I have attached the .h and .cxx that I compiled into a shared object with:
    rootcint -f matrixdict.cxx -c matrix.h LinkDef.h
    g++ -g  *.cxx -shared -o matrix.so `root-config --cflags --glibs`

The code I am running (on ROOT v5-24-00)  is the following: {
 gSystem->Load("matrix.so");

 NuMatrix1D m1;
 NuMatrix *p1 = &m1;
 NuMatrix1D *rp = dynamic_cast<NuMatrix1D*>(p1);

 cout << "POT m1: " << m1.GetPOT() << endl;
 cout << "POT p1: " << p1->GetPOT() << endl;
 cout << "POT rp: " << rp->GetPOT() << endl;   // ERROR HAPPENS HERE

}

And this gives me the following error, at line 667 of the dictionary file:

Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0xffb16639

(gdb) list

665     static long G__2vbo_NuMatrix1D_NuMatrix_0(long pobject) {
666       NuMatrix1D *G__Lderived=(NuMatrix1D*)pobject;
667       NuMatrix *G__Lbase=G__Lderived;              // <---------
This line here
causes the error, according to GDB
668       return((long)G__Lbase-(long)G__Lderived); 669     }

Is this a limitation, or is there something I am doing wrong?

Many thanks,

Nick Devenish

(I sent this yesterday, but it doesn't seem to have shown up onthe mailing list - apologies if it comes through twice)

Received on Tue Oct 20 2009 - 02:07:12 CEST

This archive was generated by hypermail 2.2.0 : Fri Oct 23 2009 - 17:50:02 CEST