Multiple function definition with gROOT.ProcessLine()

it seems like i cannot have multiple function (or class) definition in the following use case.
for example, without the int g line, the code works. but with that line, I got error: function definition is not allowed here.
is there any workaround for this (or i just not fully understand this function)?

cpp_code = """
// Function definition
int f(int i) { return i*i; }

int g(int j) { return j*j; }

// Class definition
class A {
public:
   A() { cout << "Hello PyROOT!" << endl; }
};
"""

ROOT.gROOT.ProcessLine(cpp_code)

_ROOT Version:_6.24 (conda-forge)
Platform:* centos
Compiler:* gcc9


Seems ok in C++:

A.C

// Function definition
int f(int i) { return i*i; }

int g(int j) { return j*j; }

// Class definition
class A {
public:
   A() { cout << "Hello PyROOT!" << endl; }
};
root [0] .L A.C
root [1] A b;
Hello PyROOT!
root [2] 

ROOT.gInterpreter.Declare(cpp_code)

btw what is the difference between the two ? why only one of them worked ?

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