Hello everyone,
I would like to create a structure with an integer p
and a Static vector A
whose size depends on p
. If p==0
then A
will contain 2 Float64 elements otherwise A
will contain p+1
Float64 elements. For a static array, we need to provide the size in advance but I don’t know how to do it.
Here is my code:
using StaticArrays
struct Utest
p::Int64
A::Union{SVector{2,Float64}, SVector{p+1,Float64}}
function Utest(p::Int64)
if p==0
return new(p,SVector{2,Float64})
else
return new(p,SVector{p+1,Float64})
end
end
end
UndefVarError: p not defined
Stacktrace:
[1] top-level scope at /home/mat/.julia/packages/IJulia/yLI42/src/kernel.jl:52