Hi All,
I am having a strange problem with a class with multiple inheritances. (Not a diamond Inheritance issue.)
For reference I am using root v5.34/18. ScientificLinux6 with gcc version 4.4.6.
I have two base classes
[code]class AbstractBase {
…
public:
virtual void MyMethod();
virtual void AnotherMethod() = 0;
ClassDef(AbstractBase,1);
};
class Data : public TObject {
…
ClassDef(Data,1);
};[/code]
AbstractBase is abstract but the Data class is not. I have another class on which I want to do some analysis
class myObject : public AbstractBase, public Data {
...
public:
void MyMethod();
void AnotherMethod();
ClassDef(myObject,1);
};
myObject is not abstract.
Now, I have a couple of questions:
[ul]
-
First, when I write myObject to a ROOT file, will the data members of AbstractBase also be written? Or should I avoid putting data members into AbstractBase?
-
It seems that rootcint will fail if I inherit from Data before AbstractBase. I do not understand why.
[quote]Error: abstract class object ‘myObject second’ declared /usr/local/src/root_v5.34.18/cint/cint/lib/prec_stl/utility:19:
Error: abstract class object ‘myObject second’ declared /usr/local/src/root_v5.34.18/cint/cint/lib/prec_stl/utility:19:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation[/quote]
If, however, I make AbstractBase not abstract by commenting out the purely virtual functions, the compilation works, but I run into problem 3.
- If I inherit AbstractBase first, the compilation works. But when I try to use the class in the interpreter I get the error:
It does not tell me which base class. But for reference MyMethod does access protected functions in the Data class.
[/ul]
The LinkDef.h file includes the lines
#pragma link C++ class AbstractBase+;
#pragma link C++ class Data+;
#pragma link C++ class myObject+;
Everything works fine if I just combine the AbstractBase class into the myObject class as a single class that inherits from Data. (But later, I would like to have several classes that inherit from different data classes that can all be downcast to the AbstractBase class.)
I have the feeling that the problem is originating with the fact that I am inheriting from two classes.
I have tried making AbstractBase inherit from TObject and making both inheritances virtual to solve the diamond problem. But this created problems with my IO.
Anyone have experiences with this?
Cheers,
–Jon