Issue with template type deduction for nested class in PyROOT

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18/04
Platform: CentOS7
Compiler: GCC8.3

Dear enthusiasts and experts,

I’m trying to use a function accepting a template parameter as the following:

template <typename T>
class BaseClass;

template <typename T>
void bookInstance(BaseClass<T>& object);

(the bookInstance function is actually a member function of a different class, and it’s that class for which the dictionary is generated when I compile my code) where I have nested classes from BaseClass that inherit from it. So to provide overloads for these, I would like to do

template <typename T>
class BaseClass {
  class Derived;

template <typename T>
class BaseClass<T>::Derived : public BaseClass<T>;

template <typename T>
void bookInstance(template BaseClass<T>::Derived& object);

However, calling this function with template type presumably being deduced from the argument gives me the following error from PyROOT:

import ROOT
obj = ROOT.BaseClass('int').Derived()
TypeError: can not resolve method template call for 'bookInstance'

Also, explicitly providing the template argument as the following gives me the following error:

import ROOT
obj= ROOT.BaseClass('int').Derived()
RuntimeError: could not resolve bookInstance<BaseClass<int>::Derived>(BaseClass<Derived>::Derived&)

Note the template type deduced from the argument is erroneously reported be ‘Derived’ when it is supposed to be ‘int’, as is the case if I simply print the object instance.

Interestingly, I can get my code working if I simply ignore these nested/inherited hierarchies and implement

template <typename Tany>
void bookInstance(Tany& object);

And I can effectively achieve the “specializations” that I want by defining other functions with additional parmeters that different Derived classes would have needed anyway. However, I don’t feel too good about this since ‘Tany’ is a bit too general for the types I want to implement, and also just curious as to why my original attempt is not working.

Apologies for not having a minimal example, since this is a bit deep into a piece of cod I am playing around with at the moment, but I was wondering if there was any indication of an issue or fix from the above information? Thank you for any help in advance!


I see that you are using 6.18, could you please try this with >=6.22 (preferably 6.24)? The template handling code has changed a lot since 6.22 with the new PyROOT and cppyy.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.