overloading

Function Overloading in Haskell

谁都会走 提交于 2019-12-21 17:39:56
问题 I have a structure which represents the equation of a line in the form m x + b and a structure of a point Line { m :: Double, b :: Double } deriving( Show, Eq ) Point { x :: Double, y :: Double } deriving( Show, Eq ) I want the function perpendicular that does the following: perpendicular (Line m b) (Point x y) = Line m2 b2 where m2 = (-1/m) b2 = y - m2*x if given a line and a point, or a partially applied Line perpendicular (Line m b) = Line m2 where m2 = (-1/m) if only given a Line. The

Polymorphism and overloading with static methods in C#.

匆匆过客 提交于 2019-12-21 09:38:08
问题 I have been trying to generate a Factory supposed to return a different object of a common interface (say Item ) according to the input parameter (I call it a context) of the function getItem(A context) Now, assume I define a new type of context: B which inherits from A . I wanted to return a different item depending on whether the object passed to the factory was of class B or A . I tried to do as follows (overloading the method): class Factory { static Item getItem(A context) {...} static

Is it possible to overload the ShowDialog method for forms and return a different result?

删除回忆录丶 提交于 2019-12-21 07:42:24
问题 EDIT: This method actually works great and I asked it then found the solution later. I added the correct call in the overloaded ShowDialog() method (it's not exacly an overload, or even an override, but it works just the same. My new question is the one at the bottom. I have a form in which you click one of three buttons. I have defined an enum for the returned results. I want to make the call: MyFormResults res = MyForm.ShowDialog(); I can add a new ShowDialog method with this code: public

How to detect ambiguous method calls that would cause a ClassCastException in Java 8?

限于喜欢 提交于 2019-12-21 07:39:07
问题 We are currently in the process of migrating an application from Java 7 to Java 8. After fixing a some compilation issues, I stumbled upon an issue similar to the following question: ClassCast Error: Java 7 vs Java 8. To summarise, here is a sample code that shows the issue: public class Test { public static void main(String[] args) { System.out.println(String.valueOf(getVal("xxx"))); // 7: prints the result, 8: Exception } @SuppressWarnings("unchecked") public static <T> T getVal(String

How to detect ambiguous method calls that would cause a ClassCastException in Java 8?

限于喜欢 提交于 2019-12-21 07:39:06
问题 We are currently in the process of migrating an application from Java 7 to Java 8. After fixing a some compilation issues, I stumbled upon an issue similar to the following question: ClassCast Error: Java 7 vs Java 8. To summarise, here is a sample code that shows the issue: public class Test { public static void main(String[] args) { System.out.println(String.valueOf(getVal("xxx"))); // 7: prints the result, 8: Exception } @SuppressWarnings("unchecked") public static <T> T getVal(String

Why does 'man 2 open' say that there are two kinds of open?

依然范特西╮ 提交于 2019-12-21 07:04:10
问题 I ran into this question while typing man 2 open . It says that there are two kinds of open, one with two args, and one with three! last time i checked we could not overload functions in C. How did they do this? did they write in C++? int open(const char * pathname, int flags); int open(const char * pathname, int flags, mode_t mode); 回答1: No, they just used variadic function. int open(const char * pathname, int flags, ...); This makes the last argument mode optional. The prototypes only show

Multiple Method Signatures For A Single Abstract Function/Abstract Overloading

▼魔方 西西 提交于 2019-12-21 05:46:06
问题 I have an abstract class for moving data from one database to another, and sometimes the data required to create the basic entries is different, due to the presence of a legacy table in the destination database which includes instructions for locating the data in the source. Obviously simplified, here is where the problem comes into play: abstract class foo { protected abstract function createBaseEntry($id); } Sometimes, I only need the one ID passed to this function, but in some cases I need

Why does decltype(*this) not return the correct type?

淺唱寂寞╮ 提交于 2019-12-21 04:14:44
问题 The following code was compiled with VC++ Nov 2012 CTP. But the compiler gave a warning. I just wonder whether this is a bug of VC++ Nov 2012 CTP. struct A { int n; A(int n) : n(n) {} int Get() const { return n; } int Get() { // // If using "static_cast<const A&>(*this).Get();" instead, then OK. // return static_cast<const decltype(*this)&>(*this).Get(); // Warning! } }; int main() { A a(8); // // warning C4717: 'A::Get' : recursive on all control paths, // function will cause runtime stack

How JVM finds method (parameter with the closest matching) to call in case of function overloading

梦想与她 提交于 2019-12-21 03:42:21
问题 The JVM decides which overloaded method to call at compile time. I have one example: public class MainClass{ public static void go(Long n) {System.out.println("takes Long ");} public static void go(Short n) {System.out.println("takes Short ");} public static void go(int n) {System.out.println("takes int ");} public static void main(String [] args) { short y = 6; long z = 7; go(y); go(z); go((Short)y); } } According to my understanding, it should print the following: takes Short takes Long

Overloading functions with Fortran

亡梦爱人 提交于 2019-12-20 17:39:55
问题 In Fortran 90, we can overload functions with an interface. However, according to this site, we cannot define these functions with the same arguments name. With gfortran, it does not seem to be a problem as the following code works well enough: interface check module procedure check_int, check_real end interface contains subroutine check_int(cur, dname, func_name, fname) integer, allocatable, intent(in) :: cur(:) character(*) :: dname, func_name, fname ... end subroutine subroutine check_real