I have a simple structure with an array and an associate (fitness) value.
mutable struct Solution
genome::Array
fitness
end
I want to put in a zero’d constructor so I did the following and got “I get this error LoadError: MethodError: no method matching Main.Scratch.Solution{Int64}(::Int64)”.
mutable struct Solution{T}
genome::Vector{T}
fitness
Solution(vector::Vector, fitness) = new{T}(vector, fitness)
Solution(sz::Int64) = new{T}(zeros(T, sz), 0)
end
if I do the following I get ‘LoadError: UndefVarError: T not defined’;
mutable struct Solution{T}
genome::Vector{T}
fitness
Solution{T}(vector::Vector, fitness) = new{T}(vector, fitness)
Solution{T}(sz::Int64) = new{T}(zeros(T, sz), 0)
end
I’m at a loss how to form these constructors properly.