Created
June 24, 2014 01:31
-
-
Save tmtk75/0f726d68cb63756bab6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type A struct { | |
Name string | |
} | |
type B struct { | |
A | |
} | |
type C struct { | |
*A | |
} | |
type Dog interface { | |
Bark() | |
} | |
func (self *A) Bark() { | |
print(self.Name, " says wow\n") | |
} | |
func main() { | |
a := &A{"taro"} | |
b := &B{*a} | |
c := &C{a} | |
_b := &B{} | |
_c := &C{} | |
var ad Dog = a | |
var bd Dog = b | |
var cd Dog = c | |
ad.Bark() | |
bd.Bark() | |
cd.Bark() | |
//b = a // can't assign | |
print(b.Name, "\n") | |
print(_b.Name, "\n") | |
print(_c, "\n") | |
//print(_c.Name) // panic | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment