Help me initialize a containers.Map
M = containers.Map('KeyType', 'double')开发者_JS百科
instead of giving me a map that takes keys of type double, it gives me a map that his one key (the string 'KeyType') with value 'double'
-_- What am I doing wrong?
You also have to specify the value type; So you need to write M = containers.Map('KeyType', 'double', 'ValueType', whatever)
.
Just a note: the reason that the containers.Map()
constructor requires both to be specified is that otherwise there would be ambiguity with the containers.Map(keys,values)
constructor.
>> f=containers.Map('KeyType','double','ValueType','char')
f =
Map with properties:
Count: 0
KeyType: double
ValueType: char
>> f(3)='Hello'
f =
Map with properties:
Count: 1
KeyType: double
ValueType: charf=containers.Map('KeyType','char','ValueType','double')
Note that you can also initialize it like:
f=containers.Map({3,4},{'a','foo'})
f =
Map with properties:
Count: 2
KeyType: double
ValueType: char
精彩评论