Re: segmentation violation

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Thu, 17 Nov 2005 18:39:07 +0100


Hi Vassili,

> what's wrong with the macro attached?

There are two bugs in your short macro. I've attached a corrected version. Axel.

After ".x test_list.C" I got the
> "segmentation violation" error.
>
> Regards,
>
> Vassili.
>
>
> ------------------------------------------------------------------------
>
> TList *MakeList()
> {
> TList *tlist = new TList;
> tlist->Add(new TObjString("First string"));
> tlist->Add(new TObjString("Second string"));
> tlist->Add(new TObjString("Third string"));
> return tlist;
> }
>
> void test_list()
> {
> TList *tlist;
>
> tlist = MakeList();
>
> TIter next(&tlist);
> while ((astring = (TObjString*)next())) {
> cout << astring->GetString() << endl;
> }
> }

TList *MakeList()
{

   TList *tlist = new TList;

   tlist->Add(new TObjString("First string"));
   tlist->Add(new TObjString("Second string"));
   tlist->Add(new TObjString("Third string"));
   return tlist;
}

void test_list()
{

   TList *tlist;    

   tlist = MakeList();  

   TObjString* astring=0; // gotta declare astring    TIter next(tlist); // tlist is a TList*, so that's what you pass to TIter - not &tlist    while ((astring = (TObjString*)next())) {

      cout << astring->GetString() << endl;    }
} Received on Thu Nov 17 2005 - 18:39:12 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET