In `a = Foo(12)`, the type is defined implicitly as the type of 12, which
is Int64.
In convert(Foo{Int64}, 12), you're trying to convert a Int64 to a
Foo{Int64}, and there is no
intruction for how to do it. Seehttp://docs.julialang.org/en/release-0.4/manual/types/#parametric-composite-types Abel Soares Siqueira 2016-01-04 17:01 GMT-02:00 Julia Tylors <[email protected]>: > But if I am to instantiate it normally a =Foo(12), it continues and > completes without me defining a convert method. What is really happening > here? > Thanks > > > On Monday, January 4, 2016 at 10:53:54 AM UTC-8, Julia Tylors wrote: >> >> I have a question about the convert method, Look at the example below, It >> tells me to define convert method here. >> Thanks >> >> julia> type Foo{T} >> x::T >> end >> >> julia> a = convert(Foo{Int64},12) >> ERROR: MethodError: `convert` has no method matching >> convert(::Type{Foo{Int64}}, ::Int64) >> This may have arisen from a call to the constructor Foo{Int64}(...), >> since type constructors fall back to convert methods. >> Closest candidates are: >> Foo{T}(::Any) >> call{T}(::Type{T}, ::Any) >> convert{T}(::Type{T}, ::T) >> >> >> But if I am to instantiate it normally a =Foo(12), it doesn't complete. >> And it calls some convert method which does the conversion right? How is >> this happening? >> >> Thanks >> >
