tags:

views:

31

answers:

1

I have 2 modules. Each contains a Sub with the same name. See below:

Module moduleA
    Public Sub f(ByVal arg1 As myType)
        Console.WriteLine("module A")
    End Sub
End Module

Module moduleB
    Public Sub f(ByVal arg1 As myType, ByVal arg2 As Boolean)
        Console.WriteLine("module B")
    End Sub
End Module

But the compiler complains that there's ambiguity between moduleA and moduleB.

How could this be? I have totally different signatures.

However, if I put the 2 methods into the same module, there's no ambiguity at all.

Could someone tell me why?

Many thanks.

+1  A: 

You will need to fully qualify method calls in order to stop the ambiguity. e.g. moduleA.f().

Ardman
Thanks for your reply. But why can't the compiler distinguish them just by the signature? Some kind of overloading?
smwikipedia
@smwikipedia: what is the compiler warning that you are getting?
Ardman
@Ardman, 'f' is ambiguous between declarations in Modules 'TestProject.moduleA' and 'TestProject.moduleB'.
smwikipedia
@smwikipedia: which is why you'll have to use the fully qualified name for each of these.
Ardman