2008-06-06 21:27:34 +00:00
|
|
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2009-01-20 22:40:40 +00:00
|
|
|
type C struct
|
2008-06-06 21:27:34 +00:00
|
|
|
{
|
|
|
|
a int;
|
2009-01-30 22:39:31 +00:00
|
|
|
x func(p *C)int;
|
2008-06-06 21:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
(this *C) f()int
|
|
|
|
{
|
|
|
|
return this.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
var v int;
|
|
|
|
var c *C;
|
|
|
|
|
2009-01-06 23:19:02 +00:00
|
|
|
c = new(C);
|
2008-06-06 21:27:34 +00:00
|
|
|
c.a = 6;
|
2009-01-30 22:39:31 +00:00
|
|
|
c.x = g;
|
2008-06-06 21:27:34 +00:00
|
|
|
|
|
|
|
v = g(c);
|
2008-08-12 05:07:49 +00:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 21:27:34 +00:00
|
|
|
|
|
|
|
v = c.x(c);
|
2008-08-12 05:07:49 +00:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 21:27:34 +00:00
|
|
|
|
|
|
|
v = c.f();
|
2008-08-12 05:07:49 +00:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 21:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
g(p *C)int
|
|
|
|
{
|
|
|
|
var v int;
|
|
|
|
|
|
|
|
v = p.a;
|
2008-08-12 05:07:49 +00:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 21:27:34 +00:00
|
|
|
return p.a;
|
|
|
|
}
|