I don't know if it's a bug in g++ or a lack in the specifications of C++ ... I define two classes, one inherited from the second. I allocate a table of the child, I give it to a fonction that waits for the parent class. Inside this function, when I try to access virtual functions of an element of the table other than the first, I get a segfault. It seems to be that in this function, the size of each element of the table is considered to be the one of the parent but not the one of the child. That induces a memory shift that segfault when trying to accessing the vtable ... Is there the size of the object inside the vtable ?
Created attachment 8053 [details] vtable error with virtual inheritance and tables This file shows two things : * the size of one element is different according to the context (parent class or child class) ; * this difference induce a segfault when trying to acces virtual function "VirtualAdresse()".
I think this is invalid and here is why? Basically the sizeof (A) is smaller than sizeof(B). But if you convert from B* to A* you cannot access the second element any more.
(In reply to comment #2) > I think this is invalid and here is why? > Basically the sizeof (A) is smaller than sizeof(B). > But if you convert from B* to A* you cannot access the second element any more. I'm agree it's not a conventional use of inheritance and tables. But it may be valid. Where could I find the C++ specifications used to implement g++, to get a valid solution to my problem ? Moreover, I would like to have a warning during the compilation. I think the compiler can warning on each call of non first element of a table of classes containing vtable.
You are accessing something here var[1].adresse() that definitely is not an A, but sitting somewhere between other objects. That's definitely not allowed. W.