Hello,
when one creates vector of base and derived classes like this:
import ROOT
ROOT.gROOT.ProcessLine('.L reproducer.h++g')
elements = ROOT.vector('FunctionBase*')()
elements.push_back(ROOT.FunctionBase())
elements.push_back(ROOT.FunctionDerived1()) # output: <ipython-input-7-850cc0d631fc>:1: RuntimeWarning: creating converter for unknown type "FunctionBase*&&"
elements.push_back(ROOT.FunctionDerived2())
then accessing the base class “FunctionBase” is OK:
elements[0].func1(0) # OK, returns correct result
However, accessing the second element (a derived class “FunctionDerived1”) leads to a crash:
elements[1] # crashing
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
<ipython-input-13-5aa2081a500d> in <module>
----> 1 elements[1]
SystemError: none of the 2 overloaded methods succeeded. Full details:
FunctionBase*& vector<FunctionBase*>::at(unsigned long __n) =>
problem in C++; program state has been reset
FunctionBase*const& vector<FunctionBase*>::at(unsigned long __n) =>
problem in C++; program state has been reset
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
-
Is there a way how to get on python side the correct class (either base or derived as inserted to the vector “elements” and call its member functions?
-
I would like to pass this vector of different classes (all derived from a common base class) defined on python side to given c++ class and access the elements back on python side like this:
a = ROOT.Base(elements)
a.elements[0] # ok
a.elements[1] # this, however, hangs (no output)
Any idea how to achieve 1) and 2) ? Is there a way how to get on python side the correct class type? Reproduced on ~2 weeks old master with legacy PyROOT .
Cheers,
Jiri
reproducer.h (1.4 KB)