overloading

Most terse and reusable way of wrapping template or overloaded functions in function objects

≡放荡痞女 提交于 2021-01-28 21:31:47
问题 Scenario 1: a template function pred template<typename T> bool pred(T t) { /* return a bool based on t */ } Scenario 2: a set of functions overloaded on the same name pred bool pred(A t) { /* return a bool based on t */ } bool pred(B t) { /* return a bool based on t */ } bool pred(C t) { /* return a bool based on t */ } ... Whichever of the two scenarii we're in, the bottom line is that pred does not refer to a function, and so it cannot be passed around, e.g. as a unary predicate to std:

Overloading with struct in C

匆匆过客 提交于 2021-01-28 12:21:44
问题 I am trying to write a function with the same name, but that accepts 3 different typers of structs.I don't know how I can write the parameters to do this.So in the _______, there should be proffesore, amminustratore, studente. Sp that the function can accept all 3 types of struct but only one at the time. Here is the code: int confermaCredenziali(struct ______ dati, char *uN, char *pW); struct amministratore{ char userName[MAX_LNG]; char passWord[MAX_LNG]; int stato; struct ammin *next; };

Overload: why List<String> and List<Integer> make ambiguous declaration? [duplicate]

点点圈 提交于 2021-01-28 05:06:56
问题 This question already has answers here : Method has the same erasure as another method in type (7 answers) Closed 3 years ago . Why doesn't this compile? I want to know the underlying reason. If List<String> is not the same type as List<Integer> why public String convert(List<String> strings) { return null; } and public String convert(List<Integer> strings) { return null; } make an ambiguous declaration? public class Converter { public void why() { List<String> strings = null; List<Integer>

Is it possible to narrow the types of overloaded parameters without exhaustively checking each parameter in the function body?

大兔子大兔子 提交于 2021-01-27 19:57:03
问题 I'd like to define a function which can accept parameters typed in one of two ways. For example: type Fn = { (abc: number, def: string): void, (abc: string): void, }; Given this type signature, if abc is a number, then def is a string, and if abc is a string, then def is not defined. This is clear to humans, but is there any way for Typescript to recognize it? For example, the following implementation fails: const fn: Fn = (abc: number | string, def?: string) => { if (typeof abc === 'string')

Can't use .Count() from LINQ on Dictionary

若如初见. 提交于 2021-01-27 16:39:36
问题 When I try the following in VB.NET Dim data = New Dictionary(Of String, Integer) data.Count(Function(x) x.Value > 0) 'Compile-time error! I get this compile error with .Net Fiddle: Too many arguments to 'Public Overloads ReadOnly Property Count As Integer' Visual Studio gives me this error: 'Public ReadOnly Property Count As Integer' has no parameters and its return type cannot be indexed. The following does work though: Enumerable.Where(data, Function(x) x.Value > 0).Count() 'Works! data

VS 2010 : 2 overloads have similar conversions

◇◆丶佛笑我妖孽 提交于 2021-01-27 13:46:00
问题 I don't understand what happens here class A{}; class B : A {}; void func(A&, bool){} void func(B&, double){} int main(void) { B b; A a; bool bo; double d; func(b, bo); } When compiling, Visual 2010 gives me this error on line func(b, bo); 2 overloads have similar conversions could be 'void func(B &,double)' or 'void func(A &,bool)' while trying to match the argument list '(B, bool)' I don't understand why the bool parameter isn't enough to resolve the overload. I've seen this question, and

int and float in function overloading

纵饮孤独 提交于 2021-01-27 11:43:58
问题 I have two overloaded function like below: void print(int i) { ... } void print(float f) { ... } Its giving me this error for print(1.2); : error: call of overloaded 'print(double)' is ambiguous Can anyone explain me why? 回答1: 1.2 is a double literal not a float. So the compiler requires an explicit disambiguation. 1.2f would work as that is a float literal. 回答2: 1.2 is a double literal, making the function you're trying to call ambiguous - a double can just as easily be truncated to a float

int and float in function overloading

心已入冬 提交于 2021-01-27 11:42:03
问题 I have two overloaded function like below: void print(int i) { ... } void print(float f) { ... } Its giving me this error for print(1.2); : error: call of overloaded 'print(double)' is ambiguous Can anyone explain me why? 回答1: 1.2 is a double literal not a float. So the compiler requires an explicit disambiguation. 1.2f would work as that is a float literal. 回答2: 1.2 is a double literal, making the function you're trying to call ambiguous - a double can just as easily be truncated to a float

What is the reasoning behind not allowing supertypes on Java method overrides?

南楼画角 提交于 2021-01-20 14:50:27
问题 The following code is considered invalid by the compiler: class Foo { void foo(String foo) { ... } } class Bar extends Foo { @Override void foo(Object foo) { ... } } I think that this is described in the JLS 8.4.8.1: "The signature of m1 is a subsignature (§8.4.2) of the signature of m2." and in 8.4.2: "the bounds of corresponding type variables are the same". My question is: why can't the parameter in the subtype (Bar) be a supertype of the parameter in the supertype (Foo). In the example

What is the reasoning behind not allowing supertypes on Java method overrides?

孤街醉人 提交于 2021-01-20 14:49:04
问题 The following code is considered invalid by the compiler: class Foo { void foo(String foo) { ... } } class Bar extends Foo { @Override void foo(Object foo) { ... } } I think that this is described in the JLS 8.4.8.1: "The signature of m1 is a subsignature (§8.4.2) of the signature of m2." and in 8.4.2: "the bounds of corresponding type variables are the same". My question is: why can't the parameter in the subtype (Bar) be a supertype of the parameter in the supertype (Foo). In the example