Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 16, 2004 classes vs structs | ||||
---|---|---|---|---|
| ||||
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? |
January 16, 2004 Re: classes vs structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | 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.
|
January 17, 2004 Re: classes vs structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | 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
|
January 18, 2004 linked lists, was: classes vs structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stephan Wienczny | 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 :) |
Copyright © 1999-2021 by the D Language Foundation