Hello Brett, I tried your example in LinuxRH6.2 and Windows-ME VC++6.0 and it was compiled without problem in both environment. I understand what you are trying to point out. However, may be because of different g++ version, I can not reproduce the problem. Will you give me following information? - Version of g++ - What change to following line make your compiler happy? Because I can not reproduce it, I need this information from you. Do I need to cast like (const char**) or (char *const*)? Or something else? ((const blah*)(G__getstructoffset()))->Get(libp->para[0].ref?*(char**)libp->para[0].re f :*(char**)(&G__Mlong(libp->para[0]))); Thank you Masaharu Goto >From: Brett Viren <bv@bnl.gov> >Date: Mon, 5 Mar 2001 11:29:06 -0500 (EST) >To: roottalk@pcroot.cern.ch >Subject: [ROOT] Method(const char*& x) vs. rootcint >Reply-To: Brett Viren <bv@bnl.gov> > >I want a method which sets its argument, which is a reference to a >`const char*' to a character string stored in the class. However, the >rootcint produced code doesn't use `const' which leads to a >compilation failure. > >Here is a sample class showing the problem: > > //-- blah.h -- > class blah > { > public: > blah(const char* str) : fData(str) {} > void Get(const char*& s) const { s = fData; } > private: > const char* fData; > }; > //-- end of blah.h -- > >Using this Linkdef.h: > > //-- blahLinkdef.h -- > #ifdef __CINT__ > #pragma link off all globals; > #pragma link off all classes; > #pragma link off all functions; > #pragma link C++ class blah; > #endif > // -- end of blahLinkdef.h -- > >and the following command to generate the dictionary: > > rootcint -f blahCint.cxx -c blah.h blahLinkdef.h > >and this one to compile: > > g++ -g -Wall -O -I$ROOTSYS/include -o blahCint.o -c blahCint.cxx > >I get the following compiler error (sorry for the long lines): > > blahCint.cxx: In function `int G__blah_Get_1_0(G__value *, const char *, G__param *, int)': > blahCint.cxx:86: initializing non-const `const char *&' with `char *' will use a temporary > blah.h:8: in passing argument 1 of `blah::Get(const char *&) const' > > >The offending lines in blahCint.cxx are: > > > static int G__blah_Get_1_0(G__value *result7,G__CONST char *funcname,struct G__param *libp,int hash) { > G__setnull(result7); > ((const blah*)(G__getstructoffset()))->Get(libp->para[0].ref?*(char**)libp->para[0].re f :*(char**)(&G__Mlong(libp->para[0]))); > return(1 || funcname || hash || result7 || libp) ; > } > >Line 86 is the second one in the function, the one staring with >((const blah*)...). > > >This is on Debian/GNU linux, ROOT 3.00/05 (from cvs), g++ 2.95.2 > >Am I doing something stupid or is rootcint? > >Thanks, >-Brett. > >----- End forwarded message ----- > >-- >Org: CERN, European Laboratory for Particle Physics. >Mail: 1211 Geneve 23, Switzerland >E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 >WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7677910
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:39 MET