小编Jam*_*ook的帖子

'Foo'没有匹配Foo的方法(:: Bar)

我想开始,我无法在代码的精简版本中重新创建我的问题.下面的代码按预期工作,所以这篇文章可能没有很好地提出.扩展代码太长而无法在此发布,但失败了.我将描述我正在尝试做什么,因为它可能会帮助其他人.

我创建了三种类型:Bar,Baz和Qux,它们包含Bar和Baz上的方法foo.我创建一个qux并查询它的foo

qux = Wubble.Qux()
qux.foo
Run Code Online (Sandbox Code Playgroud)

我按预期得到以下两种方法:

foo(bar::Bar)
foo(baz::Baz)
Run Code Online (Sandbox Code Playgroud)

然后,当我尝试使用bar或baz实际使用qux.foo时,它会给我一个错误'foo' has no method matching foo(::Bar).

遗憾的是,我无法使用精简代码重新创建此错误,并且实际代码不具有吸引力.在我错过的场景中,有多种方法可以解决此错误?它可能与方法扩展和函数阴影有关,就像在这篇文章中,但我无法修复.

module Wibble
type Bar
  data::Number
  function Bar(num::Number=0)
    this = new(num)
    return this
  end
end
end

module Wobble
type Baz
  data::String
  function Baz(vec::String="a")
    this = new(vec)
    return this
  end
end
end

module Wubble
using Wibble
using Wobble
typealias Bar Wibble.Bar
typealias Baz Wobble.Baz

type Qux
  foo::Function
  function Methods(this::Qux)
    function foo(bar::Bar)
      println("foo with bar says ", bar.data)
    end
    function foo(baz::Baz)
      println("foo with …
Run Code Online (Sandbox Code Playgroud)

julia

1
推荐指数
1
解决办法
100
查看次数

标签 统计

julia ×1