Quote:
Originally Posted by
nempo
Is this good or bad? I'm thinking that it needs to be this way if you want to delete an arbitrary node, or am I totally lost? :>
Don't worry you've fixed it already. O(1) is good.
Quote:
Well, I would like to use this as a sort of baseclass, as Matsp suggested, in the future, using it for inheritance. Did do some checking and testing but I couldn't figure out how to redefine 'struct member' so that the inherited class' member struct contained some more usefull information, everytime I tried to insert data into the new member structs variables the program just segFaulted. Will have to do some more testing regarding this, or if you people have some pointers on this topic?
That's the problem. You can't add members to the struct defined within this class by deriving from this class. The only way is to derive from that 'member' struct, which you cannot do from anywhere except within the 'list' class. You need to think of another solution. Either add a data pointer to 'member', or use templates.
Quote:
I did move everything into a .h file and I believe I've fixed this. Now it only comes into play when '#define DEBUG' is used.
Good stuff.
Quote:
Not sure I really understand what you are saying here. Either way, 'operator =' can't be used since it's declared private and the compiler just spits out an error message.
True I suppose, however it doesn't feel right to omit a function that you've defined. It feels like you're asking for a linker error. Who knows what a different compiler/linker might do.
Quote:
Ok, now I'm really confused ;p. If you could, please expand on that.
Have a google for "constructor initializer lists" or simliar. It is the preferred method for initiailsing variables in the constructor of a C++ class.
Quote:
The destructor now calls 'wipeList()' directly, no matter if there is a list or not. The checking wether there's a list or not is handled by that function. However, both 'wipeList()' and later 'delStart()' calls 'listExists()' which adds, as you said earlier, redundency, but I'm not sure if this can be avoided if I later want to call 'delStart()' or 'delEnd()' without calling 'wipeList()'.
Yeah don't wory about it. Just remove the reduncancy that is easy to remove and don't worry about the rest.
Quote:
Clever, that never crossed my mind, cheers :>.
No worries. Everyone start out doing things in exactly the same way.
Quote:
I managed to fix those functions, I think, not as you suggested though, but after some testing they both seem to work fine.
Well they look much better now anyway.
Quote:
I think I've managed to solve that now, rewrote 'delLink()' and 'addLink()', have a look.
Good. That kind of thing helps you more than you would think.
Quote:
Added a 'listExists()' check, should work now.
You're on to it.
Quote:
Feels like I'm learning new stuff by the minute ^^.
Isn't it good though! Never stop learning!
Quote:
ps. Updated the code in the first post to reflect the changes.
[B]EDIT: Seems I can no longer update the original post for some reason >.<.
That happens after some timeout. You might be able to login at the top of the page though, and then edit it.
You've done pretty well now. Might be good to let those changes sink in for a bit, so to speak. The next thing you would need to look into is probably either templates, or a form of iterator class, so that you aren't limited to just using 'link'.