Class can be loaded using .x but cannot be compiled .x +

Hi,

I implemented a simple class (pls see the attachment) and it works well using .x AA.cxx . However, when I try to compile it to a shared lib using .x AA.cxx+, I got the following error message: (I am using ROOT 5.19.)

[quote]Info in : script has already been loaded in interpreted mode
Info in : unloading /home/gma/light/src/./AA.cxx and compiling it
Info in TUnixSystem::ACLiC: creating shared library /home/gma/light/src/./AA_cxx.so
In file included from /home/gma/light/src/./AA.cxx:1,
from /home/gma/light/src/./filemk6rMT.h:32,
from /home/gma/light/src/./filemk6rMT.cxx:16:
/home/gma/light/src/./AA.h:13: error: ‘Bool_t AA::operator==(const AA&, const AA&)’ must take exactly one argument
In file included from /home/gma/light/src/./filemk6rMT.h:32,
from /home/gma/light/src/./filemk6rMT.cxx:16:
/home/gma/light/src/./AA.cxx:9: error: ‘Bool_t AA::operator==(const AA&, const AA&)’ must take exactly one argument
/home/gma/light/src/./filemk6rMT.cxx: In function ‘int G__filemk6rMT_1865_0_3(G__value*, const char*, G__param*, int)’:
/home/gma/light/src/./filemk6rMT.cxx:226: error: ‘class AA’ has no member named ‘operator==’
g++: /home/gma/light/src/./filemk6rMT.o: No such file or directory
Error in : Compilation failed!
Error: Function AA() is not defined in current scope :0:
*** Interpreter error recovered ***
[/quote]

I don’t understand the error message. I am not sure whether we can overload an operator in ROOT as normal c++ code or something else is wrong. Thank for your helps.

regards,

gma
AA.h (200 Bytes)
AA.cxx (215 Bytes)

Hi,

You have a C++ syntax error in your code:/home/gma/light/src/./AA.h:13: error: ‘Bool_t AA::operator==(const AA&, const AA&)’ must take exactly one argument

And indeed you have: Bool_t operator==(const AA& a, const AA& b); . In C++ if you declare operator== as a function member then the left side argument is implied (as the ‘this’ argument’), So you need to have:]code]Bool_t AA::operator==(const AA& b){return this->x==b.x || this->y==b.y;}[/code]

Philippe,
Thank for your helps. I wrote the following simple codes to use class AA and I got the error message :confused: :

root [0] .x B.cxx (const class B)10221680 Error: ~AA() declared but not defined B.cxx:4: root [1]

My codes are

][code]
#include “AA.h”

class B: public TObject{

private:
AA a;
public:
B(const AA& a_);
~B();
ClassDef(B,1);
};

#include "B.h"
ClassImp(B);
B::B(const AA& a_):a(a_){}
B::~B(){}
[/code]

My question is why the error is for AA destructor. Thank you again.

Hi,
Using .class, I found ~A() is virtual, which is strange.

Hi,

When you did:root [0] .x B.cxx (const class B)10221680 Error: ~AA() declared but not defined B.cxx:4: root [1] AA.cxx was not loaded, so the message seems accurate.
(yes, the system could have complained about more functions …)

Cheers,
Philippe.

Hi,Philippe,
I am a bit confused by your answers. My intention is: 1) define a class AA and make it a ROOT object, so I use .x AA.cxx+ 2) define a class B which uses AA, and also make it a ROOT object. I am assuming B.cxx has B.h which includes AA.h. I assume ROOT knows how to find AA’s implementation.

My poblem is if I just use .L B.cxx in ROOT,it is OK. But if I use .x B.cxx+, I always get error message. I try to understand what is going on here.

The following results may help you understand what I mean

This works even though the warnings for AA is annoying. But the following command doesn’t work.

cheers,

gma

[quote] even though the warnings for AA is annoying[/quote]I can not reproduce this problem. Which platform are you running on? Which version of ROOT are you using?

In your second case instead of loading only Broot [0] .x B.cxx+
load both A and B:root [0] .L A.cxx+ root [1] .L B.cxx+

Cheers,
Philippe.

Philippe,
Sorry for my late response. I was using ROOT 5.19, now I am using 5.20. Using your commands are OK now.

After comparing your answers to my questions, I think my confusion is about the difference between .L and .x. I thought .x is the same as .L when we are loading class definition/implementation script because we have nothing to execute but loading them. However, they had different results. If you can give me more detailed info about their difference , that will be helpful. Thank you in advance.

regards,

gma

[quote]I think my confusion is about the difference between .L and .x. I thought .x is the same as .L when we are loading class definition/implementation script because we have nothing to execute but loading them.[/quote]Actually there are different. .x always tries to execute (if it exist) the C++ command “script()”. So for you case (AA.cxx containing the definition of the class AA) there is such a function AA() which construct a (temporary) AA object.

Cheers,
Philippe.

I see. Thanks, Philippe.

cheers,

gma