T const& or const T& ... difference in PyROOT?

Hello,

My colleague came to find that, when defining a function that takes a const reference in C++ source code, “const T&” and “T const&” makes a difference when calling this function in PyROOT.

Here’s my example header file (forgive me to have a function implementation in the header… sorry)

#ifndef EMPTY_H
#define EMPTY_H

#include <iostream>
#include <TVector3.h>
class empty{
public:
  empty(){}
  virtual ~empty(){}

  void f1(TVector3 v) { std::cout<<v.x()<<std::endl; }
  void f2(const TVector3 v) { std::cout<<v.x()<<std::endl; }
  void f3(const TVector3& v) { std::cout<<v.x()<<std::endl; }
  void f4(TVector3 const& v) { std::cout<<v.x()<<std::endl; }
};
#endif

Here’s my LinkDef.h

#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class empty+;
#endif

Here’s a test python script:

from ROOT import TVector3,empty; 
e=empty()
v=TVector3(0,0,0)
e.f1(v)
e.f2(v)
e.f3(v)
e.f4(v)

Here’s an output:

0
0
0
Traceback (most recent call last):
  File "try.py", line 9, in <module>
    e.f4(v)
RuntimeError: could not resolve empty::f4(TVector3 const&)

So it succeeds for empty::f3(const TVecotr3&) but it fails for empty::f4(TVector3 const&).
Is there a reason for this?

Now if I use std::vector in place of TVector3, both f4 succeeds.
Similarly, if I define my own custom class “foo”, this follows TVector3 observation: a function that takes “const foo&” succeeds, but a function that takes “foo const&” fails.

Thank you for your time in advance.

Best regards.

Kazu

Hi,

in the end, type name lookups are string comparisons (after a bit of massaging to get the names in a uniform state). Likely something goes wrong there. Will have a look …

Cheers,
Wim