FAQ
Eh, not exactly. It depends on if the pointer implement the interface or
the struct it self implement the interface.

http://play.golang.org/p/a-YBt4Khmi

Here MyStruct3 implement MyInterface (thus *MyStruct3 implement MyInterface
as well). You may call both Foo(MyStruct3{}) and Foo(&MyStruct3{}). The
first one is passed by value, the second is passed by pointer.
While for MyStruct1, only *MyStruct1 implement MyInterface, so you can only
call by Foo(&MyStruct1{}).

On Friday, April 25, 2014 10:42:55 AM UTC-7, sco...@referabuyer.com wrote:

Ahhh ok I think my missing piece was knowing that interfaces are pointers.
In that case even if I didn't pass the struct's explicitly as
pointers(e.g. foo(struct1) instead of foo(&struct1)) then they would still
be passed by reference. That is a little confusing but I am sure it will
become clearer as I work with Go more. Thank's to all of you for the help!
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 9 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 25, '14 at 5:05p
activeApr 25, '14 at 6:04p
posts9
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase