Thanks for the reply, I should've put "reference type" in quotes.

The intention of the post was to get another's perspective to any better 
method to accomplish the example, which is to use a slice as a container of 
objects. Is there any other way besides how I implemented it?

Also I understand that everything is pass-by-value, but what exactly is 
getting passed for tryref that retains the id but not the slice of pointers?








On Sunday, November 13, 2016 at 1:03:55 AM UTC-8, Volker Dobler wrote:
>
> Go has no notion of "reference type". And pointer types are just
> that pointers. Never think about pointer types as reference types.
> There are values and pointers to values.
> Slices are a bit complicated: Please read
> https://blog.golang.org/go-slices-usage-and-internals
> carefully. It explains everything you need to know better
> than I could do here.
>
> V.
>
> Am Sonntag, 13. November 2016 05:52:49 UTC+1 schrieb 
> question....@gmail.com:
>>
>> To keep a reference to a set of objects in a slice, must it be of type 
>> []*T ?
>>
>> Is there a more elegant way to handle the following example?
>>
>> https://play.golang.org/p/73lfAntNzb
>>
>> tryref.id is an immutable value type and try.others is a reference type 
>> correct? can you explain why the id is copied properly but the reference to 
>> the object as well as tryref.others are not?
>>
>> I assume its because golang is pass by value and the type of 
>> tryref.others is not a pointer so when appending an object it creates a new 
>> instance.
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to