template<class T>
void Container<T>::Remove(const T& t) {
if(first)
{
Node*prev = nullptr;
Node*temp = first;
while(temp && t != temp->info) // t != temp->info makes my program stop working
{
prev = temp;
temp = temp->next;
}
if(temp)
{
if(!prev)
first = temp->next;
else
prev->next = temp->next;
delete temp;
}
}
}
/*
The instruction highlighted makes my program to stop working.
I think the function is well done though, so I checked the
comparison(and his opposite) operator in the class
I am passing as T parameter, which is a smart pointer class to a hierarchy:
*/
template<class T>
bool DeepPtr<T>::operator== (const DeepPtr<T>& dp) const {
return *this == dp; //tipo diverso
}
template<class T>
bool DeepPtr<T>::operator!= (const DeepPtr<T>& dp) const {
return *this != dp;
}
Honestly I can't see where the mistake is, could please someone tell me if there's something wrong?
This is where the debugger comes in. You should be able to view the variables at the time of the crash if you run the program with your debugger.
I checked it out before (recursive use of DeepPtr operator==) and after (fixed code) with debugger: (I even took screenshots but it looks like they can't be uploaded :( )
Anyway it's a really useful tool! Thank you @jlb and @Mikey Boy.
Not necessarily. The OP hasn't shown the type of member p. Assuming p is a simple pointer, then a comparison of two simple pointers is not recursive.
@AbstractionAnon
Thank you very much for the detailed explaination, it was really appreciated!
Oops, yes, I misread the code. Apologies!
No worries, thank you for being here to help and for making me think twice about it!