out of curiosity,
is there any language which can handle
the broken example ?
imho i d declare ccv as an argument of newGlobal(),
i d add an interface, so the argument is nillable,
if the arg is nill, i d set it to a default ccv/whatever/ instance
or i d make funcMap a method, func() funcMap
On Thursday, March 9, 2017 at 11:33:40 PM UTC+1, DrGo wrote:
>
> Given this declaration
> type globalOptions struct {
> ...
> ccv *ccvxml.CCV
> funcMap template.FuncMap
> }
>
> Why this does not compile
>
> //Initialize template functions
> func newGlobalOptions() *globalOptions {
> g := globalOptions{
> ccv: ccvxml.New(),
> funcMap: template.FuncMap{"List": g.ccv.List},
> //List: shortcut for ccv.List
> }
> return &g
> }
>
>
> Whereas this compiles
> func newGlobalOptions() *globalOptions {
> g := globalOptions{
> ccv: ccvxml.New(),
> }
> g.funcMap = template.FuncMap{"List": g.ccv.List}
> //List: shortcut for ccv.List
> return &g
> }
>
>
> Any cleaner way of achieving what I want which is to initialize two
> members of a struct referencing the first in the second member
> initialization?
>
> Cheers,
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.