Can't use (TString*) mystring(i) in class

In a script, I can say

TString *s = new TString(“hello”);
cout << s(3) << endl;

since these lines are in TString.h:

char& operator()(Ssiz_t i);
char operator()(Ssiz_t i) const;

but in a class that I’m writing, it gives me an error!

TString *formatstring = new TString();
ifstream fInfile;
fInfile.open(infile);
formatstring->ReadLine(fInfile);

g++ -O3 -Wall -fPIC -Wno-deprecated -D_REENTRANT -I/usr/local/root/include -c -o TEXOAsciiTree.o TEXOAsciiTree.cc
TEXOAsciiTree.cc: In method void TEXOAsciiTree::ParseFormatLine ()': TEXOAsciiTree.cc:292:formatstring’ cannot be used as a function
TEXOAsciiTree.cc:282: warning: `char *buf’ might be used uninitialized
in this function
gmake: *** [TEXOAsciiTree.o] Error 1

instead, I have to strcpy into a buffer, but I’d rather do it with just TString. I know the string is getting read out correctly, since

cout << formatstring->Data() << endl;

gives the right output.

Thanks,

Jesse Wodin

Hi,

In your case you have a pointer instead of an object. Hence you have to use something like

Cheers,
Philippe.
PS Note that the following would also work