Hi Pasha, friend functions are not class member functions. They are normal functions that may directly access class variables. Therefore you need to add a pragma statement for each friend function, like for other functions. For example this is what I use to export some TString operator friend functions: #pragma link C++ function Strip; #pragma link C++ function StrDup; #pragma link C++ function operator+(const TString&,const TString&); #pragma link C++ function operator+(const TString&,const char*); #pragma link C++ function operator+(const char*,const TString&); Cheers, Fons. > > > > Hi, > > there seems to be a problem with rootcint (CINT ?) processing of the > friend functions illustrated be the example below. Or may be somebody could > comment on what's wrong with this example ? > > Thanks, Pasha. > > ------------------------------------- v22.hh > #include "TObject.h" > > class V2 { > public: > // ****** data members > double X,Y; > // ****** constructors > V2 (); > V2 (double x0, double y0); > > double x() { return X; } > double y() { return Y; } > > friend V2 operator + (V2& v1, V2& v2); > > void set(double x, double y) { X=x; Y=y; } > > V2 operator += (V2& v) { X+=v.X; Y+=v.Y; } > > V2 add (V2& v) { return V2(X+v.X, Y+v.Y); } > > friend V2 add (V2& v1, V2& v2) ; > > ClassDef(V2,1) > > }; > > -------------------------------------- v22.cc > #include "v22.hh" > > ClassImp(V2) > > V2::V2() { X = 0.; Y = 0.; } > > V2::V2(double x0, double y0) { X = x0; Y = y0; } > > V2 operator + (V2& v1, V2& v2) { > return V2(v1.X+v2.X,v1.Y+v2.Y); > } > > V2 add (V2& v1, V2& v2) { > return V2(v1.X+v2.X, v1.Y+v2.Y); > } > > ---------------------------------------- LinkDef.h > #ifdef __CINT__ > > #pragma link off all globals; > #pragma link off all classes; > #pragma link off all functions; > > #pragma link C++ class V2; > > #endif > ---------------------------------------------------- > > Here is what I get (I compile a shared library and load it dynamically): > > /cdf/upgrade/tracking/murat/g3/test/glob>rootcint -f v22_cint.cc -c v22.hh LinkDef.h > Note: operator new() masked c > class V2 in v22.hh line 3 original base of virtual func > /cdf/upgrade/tracking/murat/g3/test/glob>gcc -shared -o v22.so -I../include -I$ROOTSYS/include v22.cc v22_cint.cc > /cdf/upgrade/tracking/murat/g3/test/glob>root > No default font loaded > ******************************************* > * * > * W E L C O M E to R O O T * > * * > * Version 1.03/01 22 August 1997 * > * Development version * > * * > * You are welcome to visit our Web site * > * http://root.cern.ch * > * * > ******************************************* > > CINT/ROOT C/C++ Interpreter version 5.13.21, Aug 12 1997 > Type ? for help. Commands must be C++ statements. > Enclose multiple statements between { }. > root [0] gSystem->Load("v22.so") > (int)0 > root [1] V2 a(1.,1.); > root [2] V2 b(2.,2.); > root [3] V2 c; > root [4] .p a > (class V2)272285080 > 0x0 double X=1 > 0x8 double Y=1 > 0x0 private: static class TClass* fgIsA > 0x0 private: long G__virtualinfo > root [5] .p c > (class V2)272285176 > 0x0 double X=0 > 0x8 double Y=0 > 0x0 private: static class TClass* fgIsA > 0x0 private: long G__virtualinfo > root [6] .p b > (class V2)272285128 > 0x0 double X=2 > 0x8 double Y=2 > 0x0 private: static class TClass* fgIsA > 0x0 private: long G__virtualinfo > root [7] c+=b; > root [8] .p c; <-------------------------------**** up to now everything is OK > (class V2)272285176 > 0x0 double X=2 > 0x8 double Y=2 > 0x0 private: static class TClass* fgIsA > 0x0 private: long G__virtualinfo > root [9] c = c+b; <-------------------------------***** call to friend function > root [10] .p c the result is wrong > (class V2)272285176 should be (4.,4.) > 0x0 double X=2 > 0x8 double Y=2 > 0x0 private: static class TClass* fgIsA > 0x0 private: long G__virtualinfo > root [11] c = a.add(b); > root [12] .p c > (class V2)272285176 > 0x0 double X=3 > 0x8 double Y=3 > 0x0 private: static class TClass* fgIsA > 0x0 private: long G__virtualinfo > root [13] c = add(c,b); <--------------------------**** call to friend function > Error: No symbol add(c,b) in current scope FILE:/var/tmp/haaa006XZ LINE:1 > *** Interpreter error recovered *** > -------------------------------------------------------------------------------- > > -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland Phone: +41 22 7679248 E-Mail: Fons.Rademakers@cern.ch Fax: +41 22 7677910
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:20 MET