构造函数中的Julia可变字典结构字典

时间:2018-08-24 12:15:49

标签: julia

是否可以使用dict变量初始化可变结构。我正在尝试以下操作:

mutable struct Global
    speciesCnt::Int64
    chromosomeCnt::Int64
    nodeCnt::Int64
    innov_number::Int64
    innovations::Dict{(Int64,Int64),Int64}
    cf::Config
    function Global(cf::Config)
        new(0,0,0,0,Dict{(Int64,Int64),Int64}(),cf) # global dictionary
    end
end

但是,当我运行它时,出现以下错误:

LoadError:TypeError:在类型,参数,预期类型中,获取了元组{DataType,DataType}。

任何帮助将不胜感激。 我正在使用Julia v 1.0

1 个答案:

答案 0 :(得分:8)

适合您的字典的类型签名是:

Dict{Tuple{Int64,Int64},Int64}

了解Julia中类型签名的最简单方法是创建所需类型的对象,然后使用typeof函数显示其类型:

julia> typeof(Dict((1,2)=>3))
Dict{Tuple{Int64,Int64},Int64}
相关问题