root icon indicating copy to clipboard operation
root copied to clipboard

[PyROOT] Error when looking for function template overload

Open etejedor opened this issue 3 years ago • 0 comments

As reported in the forum:

https://root-forum.cern.ch/t/pyroot-cppyy-cant-find-the-correct-template-overload-function/49316

The following code fails to invoke a second overload of a function template:

import cppyy
cppyy.cppdef(r"""\
        class A{};
        class B{};
        template<typename T>
        T foo1(A* h)
        {
            return (T)1;
        }
        template<typename T>
        T foo1(B* ax)
        {
            return (T)1;
        }
        template<typename T>
        T foo2(B* h)
        {
            return (T)1;
        }
        template<typename T>
        T foo2(A* ax)
        {
            return (T)1;
        }
        """)

a = cppyy.gbl.A()
b = cppyy.gbl.B()

# works
cppyy.gbl.foo1["float"](a)
# fails
cppyy.gbl.foo2["float"](a)
# works
cppyy.gbl.foo2["float"](b)
# fails
cppyy.gbl.foo1["float"](b)

etejedor avatar Mar 24 '22 06:03 etejedor