If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
splineInventory::compatibility_iterator node = treeSplineInventory.GetFirst();
while (node)
{
CRSpline *currentSpline = node->GetData();
if (someCondition==true)
treeSplineInventory.DeleteNode(nodeToDelete);
node = node->GetNext();
}
Then I managed to work it out by instantiating the node to delete and move the iterator to next element. It works, but I'm not sure if it's an orthodox approach. I'd like to hear if there is better code to do it:
wxWidgets documentation claims that wxList is std::list compatible. Therefore I suppose the orthodox way is to use the erase-remove idiom.
However, the old way you use should work but I guess std compatible containers are usually iterated differently, see e.g. wxList docs.
Edit
Here is an example of creating a list of integers and then removing odd numbers from it, without using the erase-remove idiom or Modern C++. It uses std::list but should be the same for wxList
typedef std::list<int> IntList;
IntList myList;
for ( int i = 0; i < 10; ++i )
myList.push_back(i);
IntList::iterator it = myList.begin();
while ( it != myList.end() )
{
if ( (*it) % 2 )
it = myList.erase(it);
else
++it;
}
I'm coming from the Qt world (where I stationed briefly): at that time I was advised to use dedicated containers rather than standard ones, so for example QList would have been better (?) than using std::vec or other standard containers. Is this not the case with WxWidgets? I mean, is better if I go and use standard containers rather than their Wx counterpart/implementation?
Sorry for all these questions...
papillon68 wrote:I mean, is better if I go and use standard containers rather than their Wx counterpart/implementation?
wxWidgets containers originate from the era where STL was not available on all supported platforms. AFAIK, you should use standard containers in your code, unless wxWidgets API forces you to use one of their own.