I would like to declare a table with "indexes" type
tuple PM
{
npm
nvm
}
indexes=PM[]
push!(indexes,PM(1,"s"))
push!(indexes,PM(2,"s"))
push!(indexes,PM(1,"m"))
push!(indexes,PM(2,"m"))
int countPVX[indexes]
I would like to declare a table with "indexes" type
tuple PM
{
npm
nvm
}
indexes=PM[]
push!(indexes,PM(1,"s"))
push!(indexes,PM(2,"s"))
push!(indexes,PM(1,"m"))
push!(indexes,PM(2,"m"))
int countPVX[indexes]
I am not exactly sure of what you are after, but you could make a list
as recommended by SalchiPapa, and also as in the original post... indexes = PM[]
struct PM
npm
nvm
end
indexes = PM[]
push!(indexes,PM(1,"s"))
push!(indexes,PM(2,"s"))
push!(indexes,PM(1,"m"))
push!(indexes,PM(2,"m"))
println(indexes)
The output is a list of these structs
Any[PM(1, "s"), PM(2, "s"), PM(1, "m"), PM(2, "m")]
Note, if you know what types npm
and nvm
are, I recommend stating them, i.e., npm
looks like it is always an integer
, and nvm
looks like it is always a String
struct PM
npm::Int64
nvm::String
end
you can access these elements simple as, for example:
indexes[2].npm
which in this case outputs 2
and indexes[2].nvm
would output s
.
indexes = PM[]
, as SalchiPapa suggested, would be a huge improvement indeed.
Feb 4, 2019 at 9:25
[PM(1, "s"), PM(2, "s"), PM(1, "m"), PM(2, "m")]
in one go, instead of pushing the elements. This will infer the type of the array to be Vector{PM}
, instead of Vector{Any}
.
Feb 5, 2019 at 20:09