overloading

Calling overloaded function using templates (unresolved overloaded function type compiler error) [duplicate]

不羁岁月 提交于 2019-12-06 03:46:22
This question already has an answer here : Closed 7 years ago . Possible Duplicate: How to get the address of an overloaded member function? I have a function overloaded for a set of types in a class inheritence heirarchy, e.g. Share with FutureShare and OptionShare derived. virtual unsigned rank() const { return getValue(*this, rank_, &ShareUtils::getRank); } template<typename TShare , typename TMember, typename TGetMemberFunc > TValue& getValue(const TShare& share, boost::optional<TMember>& member, TGetMemberFunc func) { if(!member) { member.reset(func(share)); } return *member; } boost:

Generic and (early?) binding in Swift 1.2

喜夏-厌秋 提交于 2019-12-06 02:59:57
func f<T>(a:T)->String { return "Generic" } func f(a:Int)->String { return "Integer" } func alias<T>(a:T)->String { return f(a) } f(1) // "Integer" f("string") // "Generic" alias(1) // "Generic" (shouldn't be "Integer" ?) alias("string") // "Generic" I understand that some form of early (static) binding is happening but I don't understand why. Is it by design or a bug? if by design then alias(a) =/= f(a) but the definition reads exactly alias(a) = f(a) ! 来源: https://stackoverflow.com/questions/32606334/generic-and-early-binding-in-swift-1-2

Java method keyword “final” and its use

半城伤御伤魂 提交于 2019-12-06 02:57:26
问题 When I create complex type hierarchies (several levels, several types per level), I like to use the final keyword on methods implementing some interface declaration. An example: interface Garble { int zork(); } interface Gnarf extends Garble { /** * This is the same as calling {@link #zblah(0)} */ int zblah(); int zblah(int defaultZblah); } And then abstract class AbstractGarble implements Garble { @Override public final int zork() { ... } } abstract class AbstractGnarf extends AbstractGarble

Lambda of “x => { throw .. }” inferred to match Func<T,Task> in overloaded method?

不问归期 提交于 2019-12-06 02:33:07
问题 I don't understand why C# ends up executing an incorrect extension method in the following LINQPad code: void Main() { // Actual: Sync Action "Expected: Sync Action".Run(x => { x.Dump(); }); // Actual: Async Task "Expected: Async Task".Run(async x => { await System.Threading.Tasks.Task.Run(() => x.Dump()); }); // Actual: Async Task!! "Expected: Sync Action".Run(x => { throw new Exception("Meh"); }); } static class Extensions { public static void Run<T>(this T instance, Action<T> action) {

Java Annotation Overloading?

♀尐吖头ヾ 提交于 2019-12-06 02:29:38
In my project, I have defined the an annotation similar to the following: (Omitting @Retention , @Target for brevity) public @interface DecaysTo { String[] value(); } Since originally writing it, our needs have changed and I have now defined an enum that I want to be able to use in place of the string: public enum Particle { ELECTRON, ANTIELECTRON, NEUTRINO, ANTINEUTRINO, ... } To avoid updating every instance of this annotation, I would like to be able to construct the annotation with either a String or a member of enum Particle without having to update every instance of this annotation to

wrapping template function and <unresolved overloaded function type

白昼怎懂夜的黑 提交于 2019-12-06 01:51:54
I have problem with my wrapping function. template <typename Iter, typename SomeFunction> void wrap(Iter first, Iter last, SomeFunction someFunction) { someFunction(first, last); } I would like to use it like this: template <typename Iter> void fill5(Iter first, Iter last) { fill(first, last, 5); } int main() { vector<int> v(100, -1); wrap(v.begin(), v.end(), fill5); } But I get test.cpp: In function ‘int main()’: test.cpp:16:40: error: no matching function for call to ‘wrap(std::vector<int>::iterator, std::vector<int>::iterator, <unresolved overloaded function type>)’ test.cpp:16:40: note:

Methods overloading

好久不见. 提交于 2019-12-06 01:41:12
When I call the EntryPoint with a parameter of type TemplateA, I always receive an exception, since the first overload is always called. What I expected to happen is that the most specific method (second overload) will be called due to dynamic binding. Any ideas why? private object _obj; public void EntryPoint(object p) { myFunc(p); } //first overload private void myFunc(object container) { throw new NotImplementedException(); } //second overload private void myFunc(TemplateA template) { _obj = new ObjTypeA(template); } //third overload private void myFunc(TemplateB template) { _obj = new

Is there a way to overload a function based on different Result type in Delphi?

随声附和 提交于 2019-12-06 01:39:22
问题 Function overloading by return type? has a very detailed answer on the rational on function overloading by return type, and from what I can see Delphi does not allow this, but are there any workarounds to overload a function based on different return type in Delphi? 回答1: The implicit and explicit conversion operators for records permit overloading by return type: namely, the type being converted to: type TFoo = record class operator Implicit(const AFoo: TFoo): Integer; class operator Implicit

Can I overload template variables?

旧街凉风 提交于 2019-12-06 01:39:02
问题 I want to declare something like this: template <typename T> constexpr enable_if_t<is_integral_v<T>, int[]> foo = { 1, 2 }; template <typename T> constexpr enable_if_t<is_floating_point_v<T>, int[]> foo = { 10, 20, 30 }; But when I try to I'm getting this error: error: redeclaration of template<class T> constexpr std::enable_if_t<std::is_floating_point<_Tp>::value, int []> foo note: previous declaration template<class T> constexpr std::enable_if_t<std::is_integral<_Tp>::value, int []> foo<T>

Work around Java's static method dispatching without Double Dispatch/Visitor patterns

末鹿安然 提交于 2019-12-06 01:26:04
I am using a class Foo that provides these methods: String overloadedMethod(Object) String overloadedMethod(Goo) Since Java statically dispatches on the non-receiver argument, I cannot just pass my value (which is an Object , but might have dynamic type Goo ) and rely on the JVM to dynamically choose the "correct" method. This is my current (ugly) work-around: Object value = ...; Foo foo = new Foo(); if (value instanceof Goo) { Goo gooValue = (Goo) value; return foo.overloadedMethod(gooValue); // -> overloadedMethod(Goo) } else { return foo.overloadedMethod(value); // -> overloadedMethod