On Wed, Apr 19, 2017 at 1:35 PM, dc0d <kaveh.shahbaz...@gmail.com> wrote:
>
> In Go there is no way to pass a reference to an instance of the
> container/enclosing type, to a function of an embedded type. What work
> around do you use for this? Any idiomatic Go way?
>
> Currently I model the shared functionality using an interface. Then the
> implementation is another struct, which takes a pointer to the container
> type and implements that interface - one could just implement the interface
> directly. But this is done for convenience and grouping the similar
> functionality. This implementation struct will then gets embedded inside the
> container/enclosing type.

Typically in Go this is the wrong question.  Wanting to pass a
reference to the enclosing type to a method of an embedded type is
often a symptom of trying to write C++ in Go.

Better to describe the whole problem, and see if people can suggest a
different approach that is more Go-like.

Ian

-- 
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