Ambiguous user defined conversions and inheritance #6050
Replies: 1 comment 41 replies
-
You directly asked, but there is no corresponding conversion operator defined for that. Instead, there are two potential different conversions that could lead to that. Specifically:
So it doesn't know which is better and gives up. |
Beta Was this translation helpful? Give feedback.
41 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Issue
The compiler cannot infer proper cast in the next 2 cases:
Question
Could the compiler compile
throw (A)d;
and/orstatic A a => new D();
because I directly asked it what typecast I want?Why
C# has no multiple inheritances, but it got interfaces with implementations, extensions, and static interfaces.
But sometimes I feel the need to express multiple inheritances so. Sometimes I can use implicit casts.
So also they feel like if I have inherited, for some reason compiler cannot decide what cast to choose even if it has direct suggestions of what to choose.
If cast can be decided, it can make the lack of multiple inheritances even less visible.
Notes
I have seen similar cases where put into
csharplang
, notroslyn
. So I have put it there too.Beta Was this translation helpful? Give feedback.
All reactions