Can i declare a const variable inside a struct in golang
8,752 views
Skip to first unread message
krma...@gmail.com
unread,
Mar 4, 2016, 5:40:09 PM3/4/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Something like
type A struct {
Root string const
Name string
}
Where Root is a constant for this struct which never changes .
Ian Lance Taylor
unread,
Mar 4, 2016, 5:44:54 PM3/4/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to krma...@gmail.com, golang-nuts
No, sorry. I assume you want something like a field Root that is set
at initialization and never changed thereafter. Go doesn't support
anything like that. It would mean that the type had no useful zero
value (
Ian
Tyler Compton
unread,
Mar 4, 2016, 6:47:16 PM3/4/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
If you're curious about why this doesn't exist, take a look at this ticket: