Re: TString question

From: Radovan Chytracek (Radovan.Chytracek@cern.ch)
Date: Sun Mar 15 1998 - 16:39:19 MET


On Sun, 15 Mar 1998, Nick van Eijndhoven wrote:

> > class MyClass {
> > 
> > private:
> > 
> >       TString  *s;
> > ...
> > 
> > public:
> > 
> >      char *GetData()
> >      {
> >      return( s->Data() );
> >      {
> > ...
> > };
> > 
> > Use it as:
> > 
> > MyClass  mcls;
> > 
> > char *ch = mcls.GetData();
> > 
> > Happy ROOTing
> > 
> >                        Radovan
> > 
> > 
> > 
> Hi Radovan,
> Since I need the TString contents in char* format in a member function
> of the same class (in which then I use the char* as an argument for the
> invokation of a member function of another class) the above construction
> should not be needed according to standard C++.
> So to me it seems we have some sort of CINT problem here.

TString.h contains the following prototype for its public method Data():

const char   *Data() const                 { return fData; }

I think that you can call the GetData() method whereever you need to get
TString data in (char *) format. To be sure you get data from TString
in ( char * ) format the function GetData() may be rewritten as :

char *GetData()
{
return( StrDup( s->Data() );
}

In this case you get (char *) instead of (const char *) because StrDup()
is defined in TString.h as:

extern char *StrDup(const char *str);     // duplicate str, free with delete []

So you can use the copy of TString data without worry
that you overwrite TString object data.

Hope this helps

                   Radovan



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:31 MET