I was trying to execute the following code:
struct Pris
length::Real
width::Real
height::Real
function Pris()
new(1,0,1)
end
function Pris(l::Integer,w::Integer,h::Integer)
if l<0 || w<0 || h<0
error("Cannot have negative values")
elseif w<l
error("Cannot have shorter width than lengths")
else
new(l,w,h)
end
end
end
by giving command z=Pris(2.4,1.4,4.6)`
This, however, throws the following error
MethodError: no method matching Pris(::Float64, ::Float64, ::Float64)
I do not understand why this is the case, since I expect that when the type of the input parameters to Pris do not conform to the functions described in the struct, they should not be entering the functions inside the struct and the output should be simply Pris(2.4,1.4,4.6) in this case.
An inner constructor, if one is defined, replaces the default constructor (see the Julia documentation at https://docs.julialang.org/en/v1/manual/constructors/#man-inner-constructor-methods).
Because your inner constructor, which is now for all intents your default constructor, requires Integer arguments, when you later try to construct your struct with Floats, the compiler cannot find a constructor that works with floating point arguments. You could simply specify Real in your inner constructor's definition's arguments instead of Integer to get the behavior you want.
Additionally, I note that you are defining a struct with an abstract type (Real) for its fields. You might want to use a type of known size such as Float64 instead, since the compiled code will often run faster.