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
|
|
|
|
|
|
|
|
type C struct
|
|
|
|
{
|
|
|
|
a int;
|
2008-09-05 20:50:34 -06:00
|
|
|
x *(p *C)int;
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func g(p *C)int;
|
|
|
|
|
|
|
|
func
|
|
|
|
(this *C) f()int
|
|
|
|
{
|
|
|
|
return this.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
var v int;
|
|
|
|
var c *C;
|
|
|
|
|
2008-12-19 04:05:37 -07:00
|
|
|
c = new(*C);
|
2008-06-06 15:27:34 -06:00
|
|
|
c.a = 6;
|
|
|
|
c.x = &g;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|