overloading

why does calling an overloaded function with arguments that don't match still work

你。 提交于 2020-01-15 06:28:08
问题 I am not able to explain why the second call ( B ) doesn't give any errors as there are two char elements, and there is no certain match for this call. Why it is called the second one ( 2. ) , but not the first ( 1. ) version? I've noticed that there are some automatic conversions. The thing that i don't get is why 'a' is promoted to int and 'c' isn't. // 1. int fun(int a, int b) { return a + b; } // 2. int fun(int a, char b) { return b - a; } // 3 int fun(float a, float b) { return a * b; }

Overloads cannot differ only by return type

江枫思渺然 提交于 2020-01-14 17:31:30
问题 I'm trying to overload a function so when using the function somewhere else, it will show the result properly that is either an array of items, void, or a single item: getSelected(type): void; getSelected(type): IDataItem; getSelected(type): IDataItem[]; getSelected(type:string, one:boolean = true):any { if (!type) { return; } if (one) { return _.reduce<IDataItem, IDataItem>(sections[type], (current: IDataItem, p: IDataItem) => { return p.selected === true ? p : current; }, void 0); } return

Function Template Overloading or Specialization for inner template type std::vector<std::vector<T>>

纵然是瞬间 提交于 2020-01-14 14:01:29
问题 How to achieve function Template Overloading for inner template type std::vector<std::vector<T>> . I have a program of overloaded templates and a complex data structure having maps, pairs and vectors. #include <iostream> #include <vector> #include <map> #include <utility> #include <typeinfo> template<typename Test, template<typename...> class Ref> //#6 struct is_specialization : std::false_type {}; template<template<typename...> class Ref, typename... Args> //#7 struct is_specialization<Ref

Can't I define defaults if I define multiple overloaded constructors in Scala?

做~自己de王妃 提交于 2020-01-14 07:15:03
问题 I've defined multiple constructors, with some default argument values in all of them. Looks correct (I can't see any ambiguity), but Scala (2.8) compiler complains: multiple overloaded alternatives of constructor define default arguments Does it mean that I can't define default values for overloaded constructors at all? Let me illustrate the situation (primitivized, of course, but illustrative): class A(subject : Double, factor : Int = 1, doItRight : Boolean = true) { def this (subject : Int,

Can't I define defaults if I define multiple overloaded constructors in Scala?

南笙酒味 提交于 2020-01-14 07:13:17
问题 I've defined multiple constructors, with some default argument values in all of them. Looks correct (I can't see any ambiguity), but Scala (2.8) compiler complains: multiple overloaded alternatives of constructor define default arguments Does it mean that I can't define default values for overloaded constructors at all? Let me illustrate the situation (primitivized, of course, but illustrative): class A(subject : Double, factor : Int = 1, doItRight : Boolean = true) { def this (subject : Int,

Documenting overloaded methods with the same XML comments

不问归期 提交于 2020-01-11 18:39:08
问题 Say I have this constructor: /// <summary> /// Example comment. /// </summary> public SftpConnection(string host, string username, string password, int port) {...} which has these overloads: public SftpConnection(string host, string username, string password) : this(host, username, password, 22) { } public SftpConnection(string host, string username, int port) : this(host, username, "", port) { } public SftpConnection(string host, string username) : this(host, username, "", 22) { } and in

Documenting overloaded methods with the same XML comments

和自甴很熟 提交于 2020-01-11 18:38:48
问题 Say I have this constructor: /// <summary> /// Example comment. /// </summary> public SftpConnection(string host, string username, string password, int port) {...} which has these overloads: public SftpConnection(string host, string username, string password) : this(host, username, password, 22) { } public SftpConnection(string host, string username, int port) : this(host, username, "", port) { } public SftpConnection(string host, string username) : this(host, username, "", 22) { } and in

C# overload with override

拈花ヽ惹草 提交于 2020-01-11 14:03:30
问题 I can surely answer to this question by myself writing a dummy test but I want to know what people think about the question. Here it is: Which method will be call when we have both at the same time overloading and overriding? I am only considering Type overloading and not arity overloading and when Type the overload are related. Let me throw you an example: class AA {} class BB : AA {} class A { public virtual void methodA(AA anAA) { Console.Write("A:methodA(AA) called"); } public virtual

C# overload with override

匆匆过客 提交于 2020-01-11 14:03:28
问题 I can surely answer to this question by myself writing a dummy test but I want to know what people think about the question. Here it is: Which method will be call when we have both at the same time overloading and overriding? I am only considering Type overloading and not arity overloading and when Type the overload are related. Let me throw you an example: class AA {} class BB : AA {} class A { public virtual void methodA(AA anAA) { Console.Write("A:methodA(AA) called"); } public virtual

concept of overloading in C++

自闭症网瘾萝莉.ら 提交于 2020-01-11 13:50:16
问题 case 1: you can overload two functions namely: void foo(int *); void foo(const int *); while in , case 2: you can not overload two functions: void foo(int); void foo(const int); I have coded and checked this concept and yet unable to find out the reason to this variation in overloading. 回答1: From Standard §13.1 Parameter declarations that differ only in the presence or absence of const and/or volatile are equivalent . That is, the const and volatile type-specifiers for each parameter type are