cannot parenthesize type in composite literal

174 views
Skip to first unread message

Abhinav Srivastava

unread,
Nov 19, 2013, 6:21:11 PM11/19/13
to golan...@googlegroups.com
Hi,

I have a struct in one package "chord" and trying to use it in another package "main".

func makeRing() *(chord.Ring) {
conf := &(chord.Config){
NumNodes:     5,
NumSuccessors: 8,
        HashBits : 160,
}

ring:=&(chord.Ring){}
ring.init(conf)
return ring
}

where Ring and Config are struct in chord package.

I get the error of "cannot parenthesize type in composite literal " while compiling "main" package.

I tried to find on net but could not get a concrete solution. 

Thanks

Abhinav

Jesse McNelis

unread,
Nov 19, 2013, 6:27:48 PM11/19/13
to Abhinav Srivastava, golang-nuts
On Wed, Nov 20, 2013 at 10:21 AM, Abhinav Srivastava <abhi1988s...@gmail.com> wrote:
ring:=&(chord.Ring){}
ring.init(conf)
return ring
}

where Ring and Config are struct in chord package.

I get the error of "cannot parenthesize type in composite literal " while compiling "main" package. 
I tried to find on net but could not get a concrete solution.

Did you try following the advice of the error message and removing the parenthesize around the type in the composite literal?
eg.

func makeRing() (*chord.Ring) {
conf := &chord.Config{
NumNodes:     5,
NumSuccessors: 8,
        HashBits : 160,
}

ring:=&chord.Ring{}
ring.init(conf)
return ring
}

Dave Cheney

unread,
Nov 19, 2013, 6:28:18 PM11/19/13
to Jesse McNelis, Abhinav Srivastava, golang-nuts
http://play.golang.org/p/Xi4FQnhZU9
> --
> 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...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages