Using TPad::AddExec

Hi,
I want to use the TPad::AddExec function, but am running into a problem using it with a class. I’ve uploaded a slightly modified copy of the triangles.C macro. The modification is that there is now a class called triangles instead of a function. Everything else is the same.

However, the macro does not work as expected, with the following output:

root [0] .L triangles2.C
root [1] triangles a(50)
root [2] Error: Function TriangleClicked() is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***
Error: Function TriangleClicked() is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***
Error: Function TriangleClicked() is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***

System:
OS X 10.6.4, gcc 4.2.1, root svn version 31880

thanks!
Peter
triangles2.C (1.55 KB)

your class function must be static and you have to change the call to AddExec as:

c1->AddExec(“ex”,“triangles::TriangleClicked()”);

Rene

great thanks!

Wondering if you can give some guidance. Rene, your solution fixed the problem peter was having, but I seem to have a new problem after the “not defined” error. Here’s sample output after I included your fix:

[code]mwoods 2 21:03:58 Downloads$ root
root [0] .L triangles.C
root [1] triangles a(32)
root [2] Error: cannot call member function without object (tmpfile):1:
triangles.C 38 void triangles::TriangleClicked();
Calling : triangles::TriangleClicked();
Match rank: file line signature

  •    0 triangles.C  38 void triangles::TriangleClicked();
    

*** Interpreter error recovered ***
Error: cannot call member function without object (tmpfile):1:
triangles.C 38 void triangles::TriangleClicked();
Calling : triangles::TriangleClicked();
Match rank: file line signature

  •    0 triangles.C  38 void triangles::TriangleClicked();
    

*** Interpreter error recovered ***
[/code]

If I change
c1->AddExec(“ex”,“triangles::TriangleClicked()”);
to
c1->AddExec(“ex”,“a::TriangleClicked()”);
then it works just fine. What’s going on? How do I adapt it for a general class method and not a class instance?

Scratch that. I missed the “and” in the solution; I wasn’t making my function static, I thought the triangles:: addition was doing that. This post (http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=3407&start=0) by Rene made me realize that and that I need to work on my reading skills. Thanks.