I'm used to working with vectors but I'm trying other data structures for fun, below I am trying to remove an item in a forward list, it doesn't have erase, only erase after but I'm struggling to understand how it works and the simplest way to remove an item. In the code below, "it" is currently pointing at the element I want to delete (via investments) , what's the easiest way to delete it? My attempt currently crashes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//class members
std::unique_ptr<std::forward_list<shares>> stocks;
std::unique_ptr<std::forward_list<shares*>> investments;
//in member function
(*it)->owned_shares -= amount;
if ((*it)->owned_shares <= 0)
{
int i = std::distance(investments->begin(), it);
auto pos = investments->begin();
std::advance(pos, i);
investments->erase_after(pos);
}