问题描述
我想用 p>
[indent = 4]
init
var h = new HashTable of string,array of int(str_hash,str_equal)
h [a] = {1,2,3}
h [b] = {5,6,7}
错误消息:
nested_generic_types.gs: 4.27-4.28:错误:语法错误,期望行结束或分号,但得到了'''
var h = new HashTable of string,int array(str_hash,str_equal)
因此,的双似乎混淆了 valac $ c $
正确的语法是什么?
错误信息与vala不同。Genie的错误信息看起来像是编译器的解析问题。
vala的错误信息更加清晰。
我的vala测试:
void main(){
var h = new HashTable< string,int []> (str_hash,str_equal);
错误信息:
错误:`int []'不是受支持的泛型类型参数,
使用`?'来赋值类型
看起来只是不支持数组,而其他所有工作。
'array'不能是任何容器中的元素(HashTable,Array,GenericArray,array ..)
一些测试:所有的作品! p>
[indent = 4]
init
var h = new HashTable of string,HashTable of字符串,int(str_hash,str_equal)
h [a] =新的字符串HashTable,int(str_hash,str_equal)
h [a] [b] = 123
stdout .printf(%d \ n,h [a] [b])
var a = new HashTable string,Array of int(str_hash,str_equal)
a [a] =新数组int
// a [a]。append_val(456)
//错误:左值预期
var x = 456
a [a]。append_val(x)
stdout.printf(%d \ n,a [a]。index(0))
var b = new HashTable的字符串,GenericArray的int(str_hash,str_equal)
b [a] =新的GenericArray int
b [a] .add(567)
stdout。 printf(%d \ n,b [a]。get(0))
var d = int的新数组array = {new Array int(),new Array of int}
//错误IF {new int,new Array of int}
var y = 321
d [0] .append_val(y)
stdout.printf(%d \ n,d [0] .index(0))
以下内容的解释:
没有正确的syntex,它只是不支持。
I want to declare a HasTable with string as it's key and array of int as it's value:
[indent=4] init var h = new HashTable of string, array of int (str_hash, str_equal) h["a"] = {1, 2, 3} h["b"] = {5, 6, 7}Error message:
nested_generic_types.gs:4.27-4.28: error: syntax error, expected line end or semicolon but got `of' var h = new HashTable of string, array of int (str_hash, str_equal)So the double of seems to confuse valac here.
What is the proper syntax?
解决方案The error message is diffrent from vala.
Genie's error message looks like a compiler's parse problem.vala's error message is more clear.
my test in vala:
void main () { var h = new HashTable<string, int[]> (str_hash, str_equal); }error message:
error: `int[]' is not a supported generic type argument, use `?' to box value typeslooks like just not support "array", and others all works.'array' can't be an element in any container(HashTable, Array, GenericArray, array..)
some test: all works!
[indent=4] init var h = new HashTable of string, HashTable of string, int (str_hash, str_equal) h["a"] = new HashTable of string, int (str_hash, str_equal) h["a"]["b"] = 123 stdout.printf ("%d\n", h["a"]["b"]) var a = new HashTable of string, Array of int (str_hash, str_equal) a["a"] = new Array of int // a["a"].append_val (456) // error: lvalue expected var x = 456 a["a"].append_val (x) stdout.printf ("%d\n", a["a"].index(0)) var b = new HashTable of string, GenericArray of int (str_hash, str_equal) b["a"] = new GenericArray of int b["a"].add (567) stdout.printf ("%d\n", b["a"].get (0)) var d = new array of Array of int = {new Array of int(), new Array of int} // ERROR IF {new Array of int, new Array of int} var y = 321 d[0].append_val (y) stdout.printf ("%d\n", d[0].index(0))an explanation from:http://blog.gmane.org/gmane.comp.programming.vala/month=20140701
No correct syntex, It just not support that.
这篇关于Genie中嵌套泛型的语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!