[ROOT] Method(const char*& x) vs. rootcint

From: Brett Viren (bv@bnl.gov)
Date: Mon Mar 05 2001 - 17:29:06 MET


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].ref:*(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.



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:38 MET