www.digitalmars.com         C & C++   DMDScript  

D - classes vs structs

reply imr1984 <imr1984_member pathlink.com> writes:
Im not quite sure how to decide about wether to use a struct or a class for a
linked list im making. Each node encapsulates a cvar for a quake like console.

The advantages of a class is that i dont need to use pointer syntax, cos
everything is by reference anyway. But its gonna be a light weight object so
maybe i should use a struct?
Jan 16 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
imr1984 wrote:

Im not quite sure how to decide about wether to use a struct or a class for a
linked list im making. Each node encapsulates a cvar for a quake like console.

The advantages of a class is that i dont need to use pointer syntax, cos
everything is by reference anyway. But its gonna be a light weight object so
maybe i should use a struct?

  
You probably want to use a struct, because linked lists are meant to be light weight. But you can encapsulate that in a class. Also you might consider making it a template so you can reuse it. ie instead of having cvar at each node, allow the user to specify anything.
Jan 16 2004
parent reply Stephan Wienczny <wienczny web.de> writes:
J Anderson wrote:
 imr1984 wrote:
 
 Im not quite sure how to decide about wether to use a struct or a 
 class for a
 linked list im making. Each node encapsulates a cvar for a quake like 
 console.

 The advantages of a class is that i dont need to use pointer syntax, cos
 everything is by reference anyway. But its gonna be a light weight 
 object so
 maybe i should use a struct?

  
You probably want to use a struct, because linked lists are meant to be light weight. But you can encapsulate that in a class. Also you might consider making it a template so you can reuse it. ie instead of having cvar at each node, allow the user to specify anything.
If he needs one he could have mine... I wrote a template linked list ones. It has all basic features... Append, Prepend, Insert, Find etc. As there are no generic foreach's, I had to write Iterators There is only one prob, I did not have much time for testing... Stephan
Jan 16 2004
parent imr1984 <imr1984_member pathlink.com> writes:
In article <bua7tc$2tvm$1 digitaldaemon.com>, Stephan Wienczny says...
J Anderson wrote:
 imr1984 wrote:
 
 Im not quite sure how to decide about wether to use a struct or a 
 class for a
 linked list im making. Each node encapsulates a cvar for a quake like 
 console.

 The advantages of a class is that i dont need to use pointer syntax, cos
 everything is by reference anyway. But its gonna be a light weight 
 object so
 maybe i should use a struct?

  
You probably want to use a struct, because linked lists are meant to be light weight. But you can encapsulate that in a class. Also you might consider making it a template so you can reuse it. ie instead of having cvar at each node, allow the user to specify anything.
If he needs one he could have mine... I wrote a template linked list ones. It has all basic features... Append, Prepend, Insert, Find etc. As there are no generic foreach's, I had to write Iterators There is only one prob, I did not have much time for testing... Stephan
Yeah host it on a website and ill test it. Who knows maybe if its good enough it could go into Phobos :)
Jan 18 2004