2008-06-06 15:27:34 -06: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 15:40:40 -07:00
|
|
|
type C struct
|
2008-06-06 15:27:34 -06:00
|
|
|
{
|
|
|
|
a int;
|
2009-01-30 15:39:31 -07:00
|
|
|
x func(p *C)int;
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
(this *C) f()int
|
|
|
|
{
|
|
|
|
return this.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
var v int;
|
|
|
|
var c *C;
|
|
|
|
|
2009-01-06 16:19:02 -07:00
|
|
|
c = new(C);
|
2008-06-06 15:27:34 -06:00
|
|
|
c.a = 6;
|
2009-01-30 15:39:31 -07:00
|
|
|
c.x = g;
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
v = g(c);
|
2008-08-11 23:07:49 -06:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
v = c.x(c);
|
2008-08-11 23:07:49 -06:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
v = c.f();
|
2008-08-11 23:07:49 -06:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
g(p *C)int
|
|
|
|
{
|
|
|
|
var v int;
|
|
|
|
|
|
|
|
v = p.a;
|
2008-08-11 23:07:49 -06:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 15:27:34 -06:00
|
|
|
return p.a;
|
|
|
|
}
|