2008-06-18 12:51:21 -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 Element interface {
|
2008-06-18 12:51:21 -06:00
|
|
|
}
|
|
|
|
|
2009-01-20 15:40:40 -07:00
|
|
|
type Vector struct {
|
2008-12-18 23:37:22 -07:00
|
|
|
elem []Element;
|
2008-06-18 12:51:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Vector) At(i int) Element {
|
|
|
|
return v.elem[i];
|
|
|
|
}
|
|
|
|
|
2009-01-20 15:40:40 -07:00
|
|
|
type TStruct struct {
|
2008-06-18 12:51:21 -06:00
|
|
|
name string;
|
|
|
|
fields *Vector;
|
|
|
|
}
|
|
|
|
|
2008-06-25 16:22:27 -06:00
|
|
|
func (s *TStruct) field(i int) *TStruct {
|
|
|
|
// works if we say
|
|
|
|
// t := s.fields.At(i);
|
|
|
|
// return t;
|
|
|
|
return s.fields.At(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2009-01-06 16:19:02 -07:00
|
|
|
v := new(Vector);
|
|
|
|
v.elem = make([]Element, 10);
|
|
|
|
t := new(TStruct);
|
2008-06-25 16:22:27 -06:00
|
|
|
t.name = "hi";
|
|
|
|
v.elem[0] = t;
|
2009-01-06 16:19:02 -07:00
|
|
|
s := new(TStruct);
|
2008-06-25 16:22:27 -06:00
|
|
|
s.name = "foo";
|
|
|
|
s.fields = v;
|
|
|
|
if s.field(0).name != "hi" {
|
2008-08-11 23:07:49 -06:00
|
|
|
panic("bad name")
|
2008-06-25 16:22:27 -06:00
|
|
|
}
|
2008-06-18 12:51:21 -06:00
|
|
|
}
|