如何从简单类型的方法访问值?
How do I access a value from a method of my simple type?
如果我想创建我的简单类型,我如何从类型方法访问它的值?
例如:
[IntegerType (rank = 6, signed = true, width = 32)]
[SimpleType]
[CCode (has_type_id = false)]
struct foo_t {
public string say_hello(){
return(@"Hello from new foo_t type");
}
public int x10(){
return this.value * 10;
}
}
这里this.value
报错The name 'value' does not exist
.
say_hello
工作正常。
答案非常简单,没有隐藏的value
字段,只有this
是当前值。
[IntegerType (rank = 6, signed = true, width = 32)]
[SimpleType]
[CCode (has_type_id = false)]
struct foo_t {
public int x10(){
return this * 10;
}
}
void main () {
foo_t foo = 5;
prin(foo.x10());
}
[Print]
inline void prin (string str) {
stdout.printf (str + "\n");
}
工作正常!
如果我想创建我的简单类型,我如何从类型方法访问它的值?
例如:
[IntegerType (rank = 6, signed = true, width = 32)]
[SimpleType]
[CCode (has_type_id = false)]
struct foo_t {
public string say_hello(){
return(@"Hello from new foo_t type");
}
public int x10(){
return this.value * 10;
}
}
这里this.value
报错The name 'value' does not exist
.
say_hello
工作正常。
答案非常简单,没有隐藏的value
字段,只有this
是当前值。
[IntegerType (rank = 6, signed = true, width = 32)]
[SimpleType]
[CCode (has_type_id = false)]
struct foo_t {
public int x10(){
return this * 10;
}
}
void main () {
foo_t foo = 5;
prin(foo.x10());
}
[Print]
inline void prin (string str) {
stdout.printf (str + "\n");
}
工作正常!