Lol, even RemoveAt will not work as you want. Really interesting logic of TList. It first will obtain pointer At(idx) and after that it’ll call Remove(ptr).
Well, I was a bit incorrect: RemoveAt/RemoveLast/etc. come from TSeqCollection, but as I can see from TList header, TList has its own methods to work directly with TList (for your specific case only - I mean only the last object in TList).
For TList you can use TObjLink object instead of TObject * pointer.
For example,
TList a;
a.Add(new TObjString(“1”));
a.Add(new TObjString(“2”));
a.Add(new TObjString(“3”));
a.Add(new TObjString(“4”));
a.Print();
a.AddFirst(a.Last());
a.Print();
//Now, remove the last element:
a.Remove(a.LinkAt(a.LastLink()));
a.Print();
Or you can obtain link for first object : a.FirstLink(), after that, “increment” such a link : lnk->Next() (or lnk->Prev()), so you can iterate
a list as if you use std::list::iterator (not exactly, but similar).
And you can remove pointed object a.Remove(lnk);
And do not forget about memory management - it’s up to you to free memory correctly.