|
|
firedraco wrote: |
---|
Your pop_front and back won't work if NULL is not convertible to T. Just throw an exception. |
Peter87 wrote: |
---|
The warnings warn you that you have not implemented the copy assignment operator and the copy constructor. This will be a problem if you try to copy the list because the predefined copy assignment operator and copy constructor will not handle the copying correctly in this case because it will just copy the two pointer members. |
|
|
iter ++
, I got errors. I know it has something to do with my increment operator, but I'm not sure why it doesn't work both ways or how to fix it since I prefer to use the postfix version.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Consider this ctor for your node class:
|
I think the first thing to do is get rid of the overloaded ++ and -- operators in your node class, since they don't belong there (and the implementations are nonsensical.) I don't really see what operator* buys you either since you can access value directly (usually a non-const version of operator* would return a reference.) |
node() : value(T()), next(NULL), prev(NULL) {}
|
|
Volatile Pulse wrote: |
---|
I'm trying to get this as close to the STL list as possible just for satisfaction. |
|
|
|
|
|
|
CPlusPlus wrote: |
---|
A reference to the first element in the list container. Member types reference and const_reference are the reference types to the elements of the container (for the default storage allocation model, allocator, these are T& and const T& respectively). |
My naive view is that you have 2 options re: the return value dilemna. 1) Return the default value for T (ie T() ) if the list is empty. How do you know if the value is good? You test the value of size. |
|
|
If you don't check if the container is empty before you call front, you're definitely not going to be checking afterward. |
How about the obvious? Throw an exception. |
if(myList.empty())
would require. I'm content with going this route as long as it is right. Thanks for the input so far, I'm just racking my mind trying to get all of this put together.
Implementing exceptions don't seem to be worthwhile in this situation since you aren't doing any other error checking than you would have been doing before without using exceptions, meaning, |
And, like you said, can't just be ignored. |
if(myList.empty())
or whatever shows that there's nothing to access is the way to go) and act accordingly.