eboyd wrote:I see the func()s but can you point me to the headers? I'm under the impression that the STL List uses a public struct Node to encapsulate the <type>data.
There's no point in making the node class public. You can never pass any of its pointers to the outside world since you only use iterators for that. Make it a private inner class.
There's a million ways to make a linked-list. I would like to keep Node a private class (hence the friends). My iterator class won't be quite like the STL iterator, mine will really just be overloaded operators allowing for things like myList++ to advance.
Hardly a million, I suspect only a few thousand if you include very odd schemes; about a dozen practical ones. These include the array list (list based on array, usually slow), the singly linked list and the doubly linked list. My personal default is the singly linked list since it's not much more complex than a doubly linked one, very efficient with space and easy to make generic.STL's list is by definition a doubly linked list but most implementations also provide an slist.
Really, I hardly ever overload operators, but Candy's convinced me to look into templates and the STL, and realistically I guess I should get used to writing re-usable code. I'm used to writing functions like:
Code: Select all
object* get_obj(){ return some_pointer; }
But I guess that's not going to help someone who expects an overloaded assignment operator, iterators, etc.
Woo! I convinced somebody!
Reusable code is infinitely more usable than normal code, especially because it's reusable. More importantly (which most people forget - I'm not in it to cut time) is that reusable code is used a lot more, tested much more thoroughly and therefore much more reliable.
At work people are used to just reimplement the list when you hit another location since it's a bit of work to make a generic one and it doesn't really pay off directly. I've added a generic one to the fray, making it a total of a few hundred implementations of a list. At least 10% of these contain an error, which almost never shows. Half of them is pure code duplication.