overloading

Java static imports

北城余情 提交于 2019-12-03 06:28:13
问题 Just by experiment I discovered that Java non static methods overrides all same named methods in scope even at static context. Even without allowing parameter overloading. Like import java.util.Arrays; import static java.util.Arrays.toString; public class A { public static void bar(Object... args) { Arrays.toString(args); toString(args); //toString() in java.lang.Object cannot be applied to (java.lang.Object[]) } } I can't find anything about this in spec. Is this a bug? If it isn't, are

What exactly is a “trailing parameter pack”

拥有回忆 提交于 2019-12-03 06:12:37
In resolving ambiguities between function template overloads, partial ordering is performed (see here for some explanations). In that website, we also learn that In case of a tie, if one function template has a trailing parameter pack and the other does not, the one with the omitted parameter is considered to be more specialized than the one with the empty parameter pack. Now, I wonder what precisely a trailing parameter pack is. Which if any of template<class ...> struct tuple { /* ... */ }; template<class T, class...Ts> void foo(tuple<T,Ts...>); template<class T, class...Ts> void bar(T, Ts..

Why overloaded methods have lower priority than instance method

本秂侑毒 提交于 2019-12-03 06:02:38
I have base class A public class A { public virtual void Method(A parameter) { Console.WriteLine(MethodBase.GetCurrentMethod()); } public virtual void Method(B parameter) { Console.WriteLine(MethodBase.GetCurrentMethod()); } } Inhereted B public class B : A { public virtual void Method(object parameter) { Console.WriteLine(MethodBase.GetCurrentMethod()); } public override void Method(A parameter) { Console.WriteLine(MethodBase.GetCurrentMethod()); } public override void Method(B parameter) { Console.WriteLine(MethodBase.GetCurrentMethod()); } } Static class S with extension method public

Encapsulating Action<T> and Func<T>?

北城以北 提交于 2019-12-03 06:01:54
I'm trying to make a design for some sort of IExecutable interface. I will not get into details, but the point is that I have several Actions that need to be executed from a base class. They may take different parameters (no big deal), and they may/may not return a value. So far, this is my design: public abstract class ActionBase { // ... snip ... } public abstract class ActionWithResultBase<T>: ActionBase { public abstract T Execute(); } public abstract class ActionWithoutResultBase: ActionBase { public abstract void Execute(); } So far, each of my concrete actions need to be a child from

Java overloading - long and float

旧时模样 提交于 2019-12-03 05:50:46
I was trying to understand java overloading rules. Everything seems fine except following, public static void main(String[] args) { long aLong = 123L; foo(aLong); } private static void foo(double aDouble) { System.out.println("Foo aDouble"); } private static void foo(Long aWrapperLong) { System.out.println("Foo Wrapper Long"); } private static void foo(int anInt) { System.out.println("Foo Int"); } private static void foo(float aFloat) { System.out.println("Foo Float"); } Why does the call resolve to foo(float aFloat) . I understand the following from JLS, This step uses the name of the method

error: overloaded 'operator<<' must be a binary operator (has 3 parameters)

北城余情 提交于 2019-12-03 05:40:43
问题 I know there are plenty of questions like these, but I couldn't find a solution that worked for me. I am trying to make simple fraction calculator than can add or subtract any number of functions and write the answer as a reduced fraction. Example: input= 3/2 + 4/ 8 , output = 2 I am trying overload operators in order to accomplish this. So in the program I am trying to develop, the input consists of an expression made of fractions separated by the operators + or - . The number of fractions

Grouping overloads in doxygen

限于喜欢 提交于 2019-12-03 05:32:25
In my library I have a lot of function overloads of the form: /// \brief Does thing. /// /// \details The thing that is done is very special. template<typename T> void do_stuff(const T& t); /// \brief Does thing repeatedly. /// \copydetails do_stuff() template<typename T> void do_stuff(const T& t, std::size_t x); This, in general, works and is quite nice but creates the same documentation section multiple times. What I want is, to group those functions together. Have on detail description and each of the overloads annotated with it's brief description. I'm also not averse to aliases that could

Why should I ever overload methods?

我只是一个虾纸丫 提交于 2019-12-03 05:32:05
问题 I found two examples in my book of overloading methods, but it doesn't explain clearly exactly why it's useful: package keepo; public class Main{ public static void main(String [] args) { int newScore = calculateScore("Tim", 500); System.out.println("New Score is" + newScore); calculateScore(75); } public static int calculateScore(String playerName, int score){ System.out.println("Player" + playerName +"Has score" + score); return score * 1000; } public static int calculateScore(int score){

How to overload Python's __bool__ method? [duplicate]

本秂侑毒 提交于 2019-12-03 05:25:41
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: defining “boolness” of a class in python I thought this should print "False", why is it printing "True"? >>> class Foo(object): ... def __bool__(self): ... return False ... >>> f = Foo() >>> if f: ... print "True" ... else: ... print "False" ... True >>> 回答1: You should define __nonzero__() in Python 2.x. It was only renamed to __bool__() in Python 3.x. (The name __nonzero__() actually predates the introduction

Overloading functions with Fortran

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:13:39
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(cur, dname, func_name, fname) real, allocatable, intent(in) :: cur(:) character(*) :: dname, func