overloading

Kotlin function overloading (varargs vs single parameter)

和自甴很熟 提交于 2019-12-24 18:09:10
问题 I have two functions check if String/Strings are blank. fun isBlank(s: String?) : Boolean { return s.isNullOrBlank() } fun isBlank(vararg strings: String) : Boolean { return strings.isEmpty() || strings.any { isBlank(it) } } So I try to call first function from the second one but seems it tries to call itself. For instance it works nice in java: public static boolean isBlank(final String string) { return string == null || string.trim().isEmpty(); } public static boolean isBlank(final String..

Kotlin function overloading (varargs vs single parameter)

送分小仙女□ 提交于 2019-12-24 18:08:01
问题 I have two functions check if String/Strings are blank. fun isBlank(s: String?) : Boolean { return s.isNullOrBlank() } fun isBlank(vararg strings: String) : Boolean { return strings.isEmpty() || strings.any { isBlank(it) } } So I try to call first function from the second one but seems it tries to call itself. For instance it works nice in java: public static boolean isBlank(final String string) { return string == null || string.trim().isEmpty(); } public static boolean isBlank(final String..

how to reduce the code of constructor overloading

主宰稳场 提交于 2019-12-24 15:53:38
问题 In my one class I have many constructors like this.. public MyData(int position,String songName,String duration, boolean e) { //initialization of above variable like int, string,string and boolean } public MyData(String songName, String artistName, String duration,String downloadPath, String songSize, String albumName,String url,String trackId, boolean e) { //initialization of above variable like String,String,String,String,String,String,String,String and boolean } and some more like above.

VS2008 C++ can't seem to inherit const overloaded method [duplicate]

蓝咒 提交于 2019-12-24 12:18:14
问题 This question already has answers here : Derived class not inheriting overloaded method from base class (2 answers) Closed 4 years ago . I was just surprised to find that the following does not compile in VS2008. The compiler complains that it cannot convert parameter 1 from const int to int& thus demonstrating that it is failing to look at the available method in the Base class. Is there a good reason for this or is it a deficiency not found in other compilers? struct Base { virtual void

Need to understand function template resolution rules

£可爱£侵袭症+ 提交于 2019-12-24 12:13:23
问题 I'm really confused by certain details of template overloading/specialization resolution rules. I tried to get some understanding on the subject by going through this article by Herb Sutter on template overloading/specialization. I'm stuck on the following specific point in the article. Here it is Consider the following code: // Example 2: Explicit specialization // template<class T> // (a) a base template void f( T ); template<class T> // (b) a second base template, overloads (a) void f( T*

When overloading compiler does not prefer primitive to Object only in case of varargs parameter presence

坚强是说给别人听的谎言 提交于 2019-12-24 12:11:58
问题 Please, could you help me to understand why compilation of first call of testVargArgsAutoboxingPriority fails? In case of second call compiler is able to select proper method by preferring primitive (first parameter) to Object but after varargs parameter addition compiler is not able to make the selection any more. Fail message is \jdk1.6.0_45\bin\javac.exe ocjp6/AutoBoxingOldStyleVarargsPriority.java ocjp6\AutoBoxingOldStyleVarargsPriority.java:7: reference to testVargArgsAutoboxingPriority

How to choose overload method suggestion order in VS?

与世无争的帅哥 提交于 2019-12-24 11:55:55
问题 Say a class has a some methods with same name and different parameters. How do I tell VS to suggest them in a particular order? 回答1: It can't be done. Simples. Overloads are ordered ascending by the number of parameters. Suspect you would indeed need to write a plug in. 回答2: You should keep to the convention of having all common parameters appear in the same order in every overload. From MSDN: Do be consistent in the ordering of parameters in overloaded members. Parameters with the same name

Overload = operator for class that shall behave like matrix [duplicate]

大憨熊 提交于 2019-12-24 07:35:32
问题 This question already has answers here : How to overload array index operator for wrapper class of 2D array? (2 answers) Closed 6 years ago . I've got a template of a class that shall behave like matrix. So the usecase is something like: Matrix matrix(10,10); matrix[0][0]=4; //set the values for the rest of the matrix cout<<matrix[1][2]<<endl; When I set the values directly in the constructor, it works well, but when I want to use matrix[x][y]=z; I get error: lvalue required as left operand

Getting a generic method to infer the type parameter from the runtime type

旧时模样 提交于 2019-12-24 04:19:25
问题 I have some extension methods for an abstract base class, let's say Pet , that themselves call a generic method that takes in that type parameter. public static Pet_ExtensionMethods { public static T PermuteFromData<T>(this T thisPet, string data) where T : Pet { T newPet = new SomeDeserializer().Deserialize<T>(data); newPet.someProperty = thisPet.someProperty; return newPet; } } This has worked great for me, as I can say things like: Dog newDog = existingDog.PermuteFromData(dogData); Cat

Scheme: overload built-in procedures, general overloading

浪尽此生 提交于 2019-12-24 04:06:06
问题 More specifically, can you overload the built-in Scheme procedure display? More generally, how can you overload any procedure in Scheme? 回答1: Scheme doesn't have overloading based on types a`la Java/C++, it's dynamically typed so it wouldn't make sense. You can do a few things though: You can overload based on the structure of the arguments: (define overload1 (case-lambda ((x y) (+ x y)) ((x y z) (+ (- x y) z)))) This doesn't really help you though since display is only going to take one