Hi Ray,
I did not get a chance to try your example yet (I will as soon as I get
back). However a short (lawyer-ish) comment. You 'declare' the operator-
as a side effect of the friend declaration. According to the C++ standard,
this is not a real declaration, it only denotes the friendship relation. It
just so happen that most compiler so far have implemented it as being also a
declaration ... but I never sure at which level of namespace they declare
it. Hence I recommend formaly declaration the free standing function in
addition to having the friend declaration.
Anyway it looks like CINT and/or your compiler decided that your friend
declaration was equivalent to:
namespace ONU {
onme operator-(onme &)
}
and thus requires a the presence of the symbol:
ONU::operator-(ONU::onme &)
However in onme.cxx you implement another function:
ONU::onme operator-(ONU::onme& Z){
...
which is the operator- in the global namespace.
Try:
namespace ONU {
onme operator-(onme& Z){
...
}
}
Cheers,
Philippe
-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Ray Fliller III
Sent: Friday, May 30, 2003 9:55 AM
To: ROOT mailing list
Subject: [ROOT] Another operator in namespace question....
Hello ROOTers,
I am using ROOT cvs from Tuesday May 27 in Linux.
I previously reported a problem with operators in namespaces which was
fixed. Thanks Philippe! But I have uncovered the "next level" in you
will... :-)
I have a namespace FOO, With a class bug, no overloaded
operators, compiled into its own library. Fine.
I have another namespace ONU, with a class onme that
inherits from FOO::bug. There is a friend overloaded uniary
minus for bug. This is compiled into ints own library and dynamically
linked to FOO::bug's library. Fine so it seems.
Here in lies the problem. If I try to link the ONU::onme library to
another library or problem I get the following error....
g++ -O2 -Wall -fPIC -D_REENTRANT -I/opt/cern/root/include -c bug.cxx
Generating dictionary bugDict.cxx...
/opt/cern/root/bin/rootcint -f bugDict.cxx -c ug.h bugLinkDef.h
g++ -O2 -Wall -fPIC -D_REENTRANT -I/opt/cern/root/include -c bugDict.cxx
g++ -shared -Wl,-soname,libBug.so -L/opt/cern/root/lib -lNew -lCore
-lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix
-lPhysics -lpthread -lm -ldl -rdynamic -L/opt/cern/root/lib -lCore -lCint
-lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix
-lPhysics -lGui -lpthread -lm -ldl -rdynamic -L/home/rainman/rfliller/ROOT
bug.o bugDict.o -o libBug.so
FOO::bug library generated......
g++ -O2 -Wall -fPIC -D_REENTRANT -I/opt/cern/root/include -c onme.cxx
Generating dictionary onmeDict.cxx...
/opt/cern/root/bin/rootcint -f onmeDict.cxx -c onme.h onmeLinkDef.h
g++ -O2 -Wall -fPIC -D_REENTRANT -I/opt/cern/root/include -c onmeDict.cxx
g++ -shared -Wl,-soname,libOnMe.so -L/opt/cern/root/lib -lNew -lCore
-lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix
-lPhysics -lpthread -lm -ldl -rdynamic -L/opt/cern/root/lib -lCore -lCint
-lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix
-lPhysics -lGui -lpthread -lm -ldl -rdynamic -L/home/rainman/rfliller/ROOT
-L\. -lBug onme.o onmeDict.o -o libOnMe.so
ONU::onme library generated.....
Now link to a program....
g++ -O2 -Wall -fPIC -D_REENTRANT -I/opt/cern/root/include -c -o dummy.o
dummy.cc
g++ -L/opt/cern/root/lib -lNew -lCore -lCint -lHist -lGraf -lGraf3d -lGpad
-lTree -lRint -lPostscript -lMatrix -lPhysics -lpthread -lm -ldl -rdynamic
-L/opt/cern/root/lib -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree
-lRint -lPostscript -lMatrix -lPhysics -lGui -lpthread -lm -ldl -rdynamic
-L/home/rainman/rfliller/ROOT -L\. -lBug -lOnMe dummy.o -o dummy
./libOnMe.so: undefined reference to `ONU::operator-(ONU::onme &)'
collect2: ld returned 1 exit status
make: *** [dummy] Error 1
rm onmeDict.cxx bugDict.cxx
Attached is code that illustrates the problem at hand. Thank you for the
time!
(Just for the record - I didn't do this! I just have to get root to work
with it! :-)
--
RAINMAN
"How much does a piece of gum cost Ray?"
"About $100."
"How much does a new car cost Ray?"
"`Bout $100."
"There goes working for NASA!"
==================================================================
Ray Fliller: rfliller@bnl.gov Office Phone: (631)-344-6124
C-A Accelerator Physics Dept. Fax: (631)-344-5954
Building 911B
Brookhaven National Lab
Upton, NY 11973 Office: Room 211
http://www.agsrhichome.bnl.gov/People/rfliller/
==================================================================
#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET