When I run the following code

type A
    v::Float64
end

type B
    v::Float64
end

Base.convert(::Type{A}, b::B) = A(b.v/2)
b = B(12)
A(b)

it fails with this error message because the implicit constructor is called.

LoadError: MethodError: `convert` has no method matching 
convert(::Type{Float64}, ::B)
This may have arisen from a call to the constructor Float64(...),
since type constructors fall back to convert methods.
Closest candidates are:
  call{T}(::Type{T}, ::Any)
  convert(::Type{Float64}, !Matched::Int8)
  convert(::Type{Float64}, !Matched::Int16)
  ...
while loading In[1], in expression starting on line 11

 in call at In[1]:2


Since the manual said "defining Base.convert(::Type{T}, args...) = 
...automatically 
defines a constructor T(args...) = ....", I expected this to work.
If I define a convert method for a built-in type like Float64, it works. Am 
I doing something wrong or is this intended? If so, it should be clearly 
stated in the manual.

Reply via email to