overloading

How does function overloading work at run-time, and why overload?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 07:05:19
问题 Let's say I have a class named ClothingStore. That class has 3 member functions, that point a visitor to the right department of the store. Member functions are ChildrenDept, MenDept and WomenDept, depending on whether the visitor is a child, a man or a woman. Function overloading can be used to make 3 functions that have same name, say, PointToDept, but take different input argument ( child, man, woman ). What is actually happening on run-time when program is executing ? My guess is that

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

六眼飞鱼酱① 提交于 2019-12-07 07:02:30
问题 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)

Defining overloaded constants in Isabelle

大兔子大兔子 提交于 2019-12-07 06:46:04
问题 How can one define a function in Isabelle that has a different definition depending on either the type of its argument, or the type of the context it is used in? For example, I might want to define a functions is_default with type 'a ⇒ bool , where each different type 'a has a potentially different "default value". (I am also assuming, for the sake of argument, that existing concepts such as zero are not suitable.) 回答1: This kind of overloading looks like a perfect fit for type classes. First

Does Php support method overloading

别来无恙 提交于 2019-12-07 06:31:21
问题 Does php support method overloading. While trying below code it suggests it supports method overloading. Any views class test { public test($data1) { echo $data1; } } class test1 extends test { public test($data1,$data2) { echo $data1.' '.$data2; } } $obj = new test1(); $obj->test('hello','world'); As i have overload the method it gives the output as "hello world". Above code snippet suggests php supports method overloading. So my question is does php support method overloading. 回答1: You

Kotlin: Possible to modify functions during compile time through metaprogramming?

a 夏天 提交于 2019-12-07 05:56:59
问题 In dynamic languages like JavaScript/Python, it's possible to overwrite or "modify" functions during run-time. For example, in order to modify the alert function in JS, one could do: const _prev_alert = window.alert; window.alert = function() { _prev_alert.apply(this, arguments); console.log("Alert function was called!"); } This would output "Alert function was called!" to the console every time the alert function is called. Now, obviously something like this would be impossible during

Overloading of C++ templated functions

时光怂恿深爱的人放手 提交于 2019-12-07 05:30:26
问题 I would think that the following code should be working, but both g++ and clang++ return the exact same error (although Visual C++ 2012 doesn't). #include <iostream> #include <tuple> template <int N, typename T> struct A { }; template <typename Tuple> double result(const Tuple& t, const A<0, typename std::tuple_element<0, Tuple>::type>& a) { return 0; } template <typename Tuple> double result(const Tuple& t, const A<std::tuple_size<Tuple>::value-1, typename std::tuple_element<std::tuple_size

Duplicate Method while Method-Overloading

社会主义新天地 提交于 2019-12-07 05:27:13
问题 Following code gives compilation error with error "Duplicate Method" static int test(int i){ return 1; } static String test(int i){ return "abc"; } This is expected as both the overloaded method have same signature and differ only in return type. But the following code compiles fine with a warning: static int test1(List<Integer> l){ return 1; } static String test1(List<String> l){ return "abc"; } As, we know the Java Generics works on Erasure, which mean in byte-code, both these method have

How to override functions from String class in C#

一世执手 提交于 2019-12-07 04:23:11
问题 For example, I need to see if a string contains a substring, so I just do: String helloworld = "Hello World"; if(helloworld.Contains("ello"){ //do something } but if I have an array of items String helloworld = "Hello World"; String items = { "He", "el", "lo" }; I needed to create a function inside the String class that would return true if either of the items inside the array is contained in the string, for example. I would like to override the function Contains(string) with Contains

Understanding overload resolution ranking involving user defined conversion

若如初见. 提交于 2019-12-07 03:22:32
问题 I am trying to understand overload resolution . First let's consider this first case: struct int1{ int val; operator int&()&{ return val; } operator const int &() const&{ return val; } }; void f(int &){} //f#1 void f(const int&){} //f#2 void test1(){ int1 x; f(x); //Conversion sequence for f#1: // - int_wrapper& --> int1::operator int& // => Ranking: user defined conversion rank //Converison sequence for f#2: // - int1& --> int1::operator int & --> const int& // - int1& --> const int1 & -->

The method is ambiguous for the type Error

前提是你 提交于 2019-12-07 03:13:08
问题 I am trying to understand how Overloading in JAVA works and trying to get grasp of various overloading rules that are applied in case of widening, autoboxing and varargs in JAVA. I am not able to understand what is happening in the following scenario: package package1; public class JustAClass { public static void add(int a, long b) { System.out.println("all primitives"); } //public static void add(Integer a, long b) { // System.out.println("Wraper int, primitive long"); //} public static void