Re: TString question

Nick van Eijndhoven (Nick@fys.ruu.nl)
Sun, 15 Mar 1998 16:09:52 +0100 (MET)


*** Radovan Chytracek wrote :
>
> On Sun, 15 Mar 1998, Nick van Eijndhoven wrote:
>
> > char* ch;
> > TString* s=new TString("small_test");
> > ch=(char*)s->GetContents();
> Try the following:
>
> char *ch;
> TString* s = new TString("small_test");
> ch = s->Data();
>
> or
>
> ch = StrDup(s->Data());
>
> Happy ROOTing
> Radovan
>
>
>
Hi Radovan,
Thanks for your quick reply.
Indeed I tried also :

TString* s; // In the private area of my class

s = new TString("small_test"); // In one of the initialisation
// member functions

char* ch=s->Data(); // In another member function.

However, the last statement gives me an error message in ROOT

"illegal pointer to class object".

I also tried : char* ch=(char*)s->Data();
char* ch=(const char*)s->Data();

but nothing worked.

Note that I have a small macro test.cc in which I create an object
of my class, through which the above statements are invoked via the
various member functions.

The strange thing however is that when I type the above statements in
by hand in my ROOT session, everyrhing looks o.k.
Has someone any idea ?


Cheers,

_/_/ _/ _/ _/_/_/_/ _/ _/
_/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/_/
_/ _/_/ _/ _/ _/ _/
_/ _/ _/ _/_/_/_/ _/ _/

*----------------------------------------------------------------------*
Dr. Nick van Eijndhoven Department of Subatomic Physics
email : nick@fys.ruu.nl Utrecht University / NIKHEF
tel. +31-30-2532331 (direct) P.O. Box 80.000
tel. +31-30-2531492 (secr.) NL-3508 TA Utrecht
fax. +31-30-2518689 The Netherlands
WWW : http://www.fys.ruu.nl/~nick Office : Ornstein lab. 172
----------------------------------------------------------------------
tel. +41-22-7679751 (direct) CERN PPE Division / ALICE exp.
tel. +41-22-7675857 (secr.) CH-1211 Geneva 23
fax. +41-22-7679480 Switzerland
CERN beep : 13+7294 Office : B 160 1-012
*----------------------------------------------------------------------*