overloading

C# Method Overload Problem With Class Derived From Generic Abstract Class

旧街凉风 提交于 2019-12-06 01:11:00
问题 I am working on a project, and I have a generic abstract type that takes a type parameter that is itself derived from the abstract type. If you want to know why I would do this, please see this question. I have run into an interesting problem with overloading a method in a derived class that is defined in the abstract class. Here is a code sample: public abstract class AbstractConverter<T, U> where U : AbstractConvertible where T : AbstractConverter<T, U> { public abstract T Convert(U

Cannot deduce template argument that is a function

女生的网名这么多〃 提交于 2019-12-06 00:33:46
问题 Why cannot F be deduced for proxy() ? It should be possible because I am restricting it - only for functions that return an int . #include <utility> #include <iostream> #include <type_traits> using namespace std; int foo(int bar) { cout << "int" << endl; return 2; } float foo(float bar) { cout << "float" << endl; return 1; } template <typename F, typename... Args> typename enable_if< is_same< typename result_of<F(Args...)>::type, int >::value, typename result_of<F(Args...)>::type >::type

ambiguous reference to overloaded definition, from a Java library

℡╲_俬逩灬. 提交于 2019-12-05 19:48:55
I was tying to convert this example for JsonPath to Scala. It should be easy with java like: List<String> authors = JsonPath.read(json, "$.store.book[*].author"); Which I converted to this Scala: val authors = JsonPath.read(json, "$.store.book[*].author"); Where json is a String. But I get this compile error. ambiguous reference to overloaded definition, both method read in object JsonPath of type [T](x$1: String, x$2: String, x$3: <repeated...>[com.jayway.jsonpath.Filter[_]])T and method read in object JsonPath of type [T](x$1: Any, x$2: String, x$3: <repeated...>[com.jayway.jsonpath.Filter[_

Call a functor with a specific function from an overload set

余生长醉 提交于 2019-12-05 19:34:35
Context In mathematics-related context, I'd like to define functors working on <cmath> functions. For the purpose of this question, we will be using std::invoke as our functor. This is ill-formed (live demo) : std::invoke(std::sin, 0.0); (g++-8.1) error: no matching function for call to 'invoke(<unresolved overloaded function type>, double)' Indeed, std::sin is an overload set and the compiler lacks the type information to choose one of those functions. Question How could I name a specific function from an overload set? With what could we replace LEFT and RIGHT so that the following is well

Can “overloading” via FlexibleInstances return different types, or match on typeclasses?

对着背影说爱祢 提交于 2019-12-05 18:57:37
I'm curious about what kind of "overloading" can be accomplished in Haskell's type classes via "FlexibleInstances". As a simple test, here is a case of an AdjusterType datatype. It defines an adjust operation that will add a different amount to its value based on whether it contains an Integer or a Double: {-# LANGUAGE FlexibleInstances #-} class Adjustable a where adjust :: a -> Double data AdjusterType a = Adjuster a deriving Show instance Adjustable (AdjusterType Integer) where adjust (Adjuster a) = fromIntegral (a + 20) instance Adjustable (AdjusterType Double) where adjust (Adjuster a) =

Java: How can one put to use constructor overloading in enums?

主宰稳场 提交于 2019-12-05 17:42:05
I am working with enumerations in Java. As I can see, it is possible to overload an enumeration constructor. My question is it possible at all to benefit from constructor overloading in this context given that as far as I understand it is possible neither to call it by yourself no to force the compiler to call a particular one that you would like to call? Appreciate the time your take to clarify that stuff to me and hope it would also be useful for others who might have the same question in mind. You do call it - when setting the enum values. For example: public enum Person { FRED("Frederick",

How do I call overloaded static methods from the .net framework in Powershell?

回眸只為那壹抹淺笑 提交于 2019-12-05 14:09:02
Below is a transcript of what I've tried and what happens. I'm looking for how to call a specific overload along with an explanation of why the following does not work. If your answer is "you should use this commandlet instead" or "call it twice" please understand when I don't accept your answer. PS C:\> [System.IO.Path]::Combine("C:\", "foo") C:\foo PS C:\> [System.IO.Path]::Combine("C:\", "foo", "bar") Cannot find an overload for "Combine" and the argument count: "3". At line:1 char:26 + [System.IO.Path]::Combine <<<< ("C:\", "foo", "bar") + CategoryInfo : NotSpecified: (:) [],

How do I call the original function from the overloaded function in a category?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 12:45:29
In Objective-C, I have a category for a class: @interface UILabel(CustomInit) - (id)initWithCoder:(NSCoder *)coder; @end What I'm doing is writing a custom init function that does some extra stuff, and what I'd like to do, is in this custom init function, call the UILabel's base initWithCoder. Is this possible? How so? EDIT Thanks. Ok, so my plans moot. Can't just overload initWithCoder. Is there a way to achieve the same functionality (where all UILabels get this added initialization step) without overloading initWithCoder? Or perhaps is there sample code for the UILabel's initWithCoder that

Ambiguous Reference/Value Versions of Functions

♀尐吖头ヾ 提交于 2019-12-05 12:45:13
Consider the following function prototypes: void Remove(SomeContainer& Vec, const std::size_t Index); SomeContainer Remove(SomeContainer Vec, const std::size_t Index); The second is implemented in terms of the first. That is to say, they are functionally identical in every way except that one is pass-by-reference and the other is pass-by-value. However, GCC says these are ambiguous in cases like this, even though the first form is the only one that does not return a value: Remove(SomeContainer, 123); Is there any workaround to this, or do I have to come up with different names for each form?

Haskell ad hoc polymorphism

≯℡__Kan透↙ 提交于 2019-12-05 12:23:30
I'm trying to get my head around ad-hoc polymorphism in haskell, that is having the same function provide different behaviour for different argument types. But while the following test code compiles {-# LANGUAGE MultiParamTypeClasses #-} class MyClass a b where foo :: a -> b instance MyClass Bool Int where foo True = 0 foo False = 1 instance MyClass Double Double where foo x = -x if I try to call it using something like foo True ghci yells at me: No instance for (MyClass Bool b0) arising from a use of `foo' The type variable `b0' is ambiguous Possible fix: add a type signature that fixes these