Hey Ankan!
I was just making a sugestion about the C++ forum, i'm sorry if it sounded as an accusation or something.
I can understand you confusion, it happened to me as well, and it generally happens to anyone that "migrates" from C to C++, which i understand is your case as well. A lot of C++ stuff will sound useless to you (like making first-last members private) untill you begin to think in a OO manner. Like i said, i had these problems myself, so you will probably spend some time familiarizing with the idea of OO.
It's a good point that you mentioned the OOP forum which should me more visited that it is now.
First of all, i appologize for the huge mistake i made in the destructor!
Second:
The idea is to separate as much as possible the objects and specify them a strictly related behavior.
This would mean that in the
Member class you only should manipulate a
Member object, that is setting, retrieving data and [red]not sorting the list the member it belongs to[/red]!
Thats the container's business... The container will implement behavior specific to what a container should do, that is adding, replacing, deleting, sorting data.
DIVIDE ET IMPERA.
Third of all:
Why make first and last private if the member class already has private members?
Well... This is somehow a reccurent question...
Because first & last belong to the
Container class, so you simply don't want to let anybody to modify them/
Why let somebody say:
Code:
member = NULL; // somewhere in the code...
container->first = member;
or setting unintentionally that value to NULL when you can say:
Code:
member = NULL; // somewhere in the code...
container->setFirst(member);
// and then, in the container implementation:
Member * Container::setFirst(Member * node)
{ Member ret = node;
if (node)
{ ret = first;
first = node;
}
return ret;
}
Here, for example, the setFirst function returns the previous
first element or NULL.
Hope this helps a little bit. Again, i appologize if i am making some mistakes and welcome anybody to correct me.
[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...