ambiguity

Calling ambiguously overloaded constructor in Java

五迷三道 提交于 2019-12-11 03:04:19
问题 I just saw this C# question and wondered, if something similar could happen in Java. It can, with class A<T> { A(Integer o) {...} A(T o) {...} } the call new A<Integer>(43); is ambiguous and I see no way how to resolve it. Is there any? 回答1: Yes, members of a parameterized type JLS3#4.5.2 can end up in conflicts that are precluded in a normal class declaration(#8.4.8). It's pretty easy to come up with many examples of this kind. And in Java, neither constructor in your example is more

About multiple inheritance and ambiguity

女生的网名这么多〃 提交于 2019-12-10 23:39:45
问题 In the following example: class A { public: virtual void f() { cout << "a" << endl; } virtual void h() { cout << "A" << endl; } }; class s1 : public A { public: virtual void f() { cout << "s1" << endl; } }; class s2 : public A { public: virtual void h() { cout << "s2" << endl; } }; class GS : public s1, public s2 { public: }; int main() { s1 *q = new GS; q->h();//no problem GS a; a.h();//error } Why does a.h(); give an ambiguity error yet q->h(); doesn't? Doesn't *q have an instance of GS

Ambiguity not picked up by compiler

☆樱花仙子☆ 提交于 2019-12-10 18:37:15
问题 I had to spent some time in finding and fixing a bug that I managed to isolate in the following code: #include <iostream> struct A { std::string S; A(const std::string s) { S = s; } }; void f1(A a) { std::cout << "f1:a.S = " << a.S << "\n"; } void f1(const std::string s) { std::cout << "f1:s = " << s << "\n"; } void f2(A a) { std::cout << "f2:a.S = " << a.S << "\n"; } int main() { f1(A("test")); f1(std::string("test")); f2(A("test")); f2(std::string("test")); return 0; } The bug was caused by

Understanding a case of Haskell Type-Ambiguity

泪湿孤枕 提交于 2019-12-10 15:32:00
问题 I wrote a Haskell program and got a compile error I don't understand. The program should: Get the command line arguments Concatenate tokenized arguments back to a single String Read the String into a NestedList data type Flatten the NestedList into a List Print the List Unfortunately, it won't compile because of a type ambiguity. Haskell Code: {- Run like this: $ ./prog List [Elem 1, List [Elem 2, List [Elem 3, Elem 4], Elem 5]] Output: [1,2,3,4,5] -} import System.Environment import Data

Why does vb.net reject assignment to nested covariant interface as “ambiguous”

a 夏天 提交于 2019-12-10 15:07:00
问题 In the code: Interface ISelf(Of Out TMe) End Interface Class SomeBase Implements ISelf(Of SomeBase) End Class Class SomeDerived Inherits SomeBase Implements ISelf(Of SomeDerived) End Class Module ISelfTester Sub TestISelf() Dim z7 As New SomeDerived Dim z8 As ISelf(Of SomeDerived) Dim z9 As ISelf(Of ISelf(Of SomeDerived)) z8 = z7 z9 = z8 z9 = z7 ' Why is this illegal? End Sub End Module The assignment directly from Z7 to Z9 yields the message "Error 13 Option Strict On does not allow implicit

.ctor is ambiguous because multiple kinds of members with this name exist in class

旧街凉风 提交于 2019-12-10 14:56:38
问题 I am replicating a situation that I am facing. Let's say we have an assembly, with C# class as: public class Program { int n = 0; public void Print() { Console.WriteLine(n); } public Program() { } public Program(int num = 10) { n = num; } } We refer the above assembly in VB.NET project and trying to create an instance of the Program class: Module Module1 Sub Main() Dim p As New Program() p.Print() p = New Program(20) p.Print() Console.ReadLine() End Sub End Module The VB.NET project is not

Resolve overload ambiguity with SFINAE

雨燕双飞 提交于 2019-12-10 10:36:52
问题 I've found similar cases, but they usually ended up doing something along the lines of what I (think) I'm doing here. I want to be able to call a function with one or more parameters, obviously, if the function exists with overloads with multiple parameters, the correct version cannot be deduced without help. As I am specifying the number of arguments as well, I figured this would be enough information for the compiler to deduce the correct overload. This doesn't seem to be the case and I

Why does direct list initialization causes ambiguity for type reference cast if cast operators to the type and reference to the type are declared?

孤街醉人 提交于 2019-12-10 02:02:24
问题 The question rose in context of this answer. Consider an example: struct foo { int value; operator int&(){ return value; } operator int(){ return value; } }; int main () { int &a(foo{}); // #1 //int &b{foo{}}; // #2 -- ambiguity int &c = foo{}; // #3 //int &d = {foo{}}; // #4-- ambiguity int &d { a }; // #5 int &e = { a }; // #6 (void)a; (void)c; (void)d; (void)e; } I don't understand why does #2 and #4 cause ambiguity while #1 and #3 does not. So the question is - why does direct list

Ambiguous XML schema

喜欢而已 提交于 2019-12-09 17:25:43
问题 I'm trying to produce a pretty simple XML schema for an XML similar to the following: <messages> <item> <important_tag></important_tag> </item> <item> <important_tag></important_tag> <tag2></tag2> </item> <item> <tag2></tag2> <tag3></tag3> </item> </messages> The idea is that <important_tag> will have a specific definition AND it may or may not appear under <item> . It may also appear more than once. Additionally, there may be other tags before or after <important_tag> that I can not name in

Ambiguity with Action and Func parameter

泄露秘密 提交于 2019-12-09 07:59:07
问题 How is it possible that this code TaskManager.RunSynchronously<MyObject>(fileMananager.BackupItems, package); causes a compile error The call is ambiguous between the following methods or properties: 'TaskManager.RunSynchronously<MyObject>(System.Action<MyObject>, MyObject)' and 'TaskManager.RunSynchronously<MyObject>(System.Func<MyObject, bool>, MyObject)' when signature of the action is public void BackupItems(MyObject package) and "ambiguous" methods are static class TaskManager { public