overloading

Is this Overloading, methods with same name in different classes and different signature?

混江龙づ霸主 提交于 2019-12-10 03:12:35
问题 If I have the following code in Java: class A { public int add(int a , int b) { return (a+b); } } class B extends A { public float add(float a , float b) { return (a+b); } In this particular case the sub-class isn't exactly overriding the base class's add function as they have different signatures and the concept of overloading occurs only if they are in the same scope. So, is the function add(float , float) in the sub-class B treated as an entirely new function and the concept of overloading

Method overloading and generics

℡╲_俬逩灬. 提交于 2019-12-10 02:52:32
问题 Java typically prefers normal methods to generic ones when choosing which overloaded method is correct, which could generate the following sscce: public class GenericsTest { public static void main(String[] args) { myMethod(Integer.class, 10); myMethod(String.class, "overloaded method"); } public static <T> void myMethod(Class<T> klass, T foo) { System.out.println("hello world"); } public static <T> void myMethod(Class<T> klass, String bar) { System.out.println(bar); } } Output: hello world

What set of functions is considered when resolving overloaded functions assigning to default parameter values?

大兔子大兔子 提交于 2019-12-10 01:14:09
问题 Consider the function bar below, whose parameter has a default value initialized from an invocation of an overloaded foo : #include <iostream> int foo(int x) { std::cout << "foo(int)" << std::endl; return 0; } template<typename T> void bar(T a, int x = foo(T(0))) {} double foo(double x) { std::cout << "foo(double)" << std::endl; return 0; } int main() { bar<int>(1); bar<double>(1); return 0; } I expect this program to output foo(int) foo(double) corresponding to foo 's two overloads which are

Checking whether a non-hardwired member function exists with SFINAE

眉间皱痕 提交于 2019-12-09 23:18:01
问题 I want to create proxies for member functions and operators. They must have the same return type and parameters, and must be good for several classes, which are given as template parameters. Even if the class does not have the particular member function or operator, I want it to compile instead of failing with an error, essentially SFINAE. If X has a method f() and Y does not have any method named f , I need Proxy<X> to have an f() as well that calls X::f() , and I need Proxy<Y> to compile

overloading new and delete

寵の児 提交于 2019-12-09 21:25:06
问题 I try to follow this article: http://flipcode.com/archives/How_To_Find_Memory_Leaks.shtml to overload my new and delete functions in order to track memory leaks. however - if I try to compile, I get a C2365: "operator new": redefinition; previous definition was a "function" in the file xdebug xdebug gets included in xlocale - however, i can't find where my project is including xlocale I'm using MFC for multithreading in my project. Can someone tell me how I can get my memory leak tracking to

Function overloading vs. default parameters in VB.NET?

女生的网名这么多〃 提交于 2019-12-09 17:43:05
问题 In VB.NET, which is better to use: function overloading or default parameters? 回答1: Is the code going to be used by other languages? If so, that swings the balance towards overloads while still bearing Hamish's answer in mind. In particular, C# doesn't support optional parameters - yet... Admittedly this wouldn't actually prevent someone using your code from C#, it just might be a pain for them. If there are a lot of parameters and they logically represent something, you might want to

Method overload resolution using dynamic argument

为君一笑 提交于 2019-12-09 17:03:08
问题 This may have been answered before. I see many "dynamic method overload resolution" questions, but none that deal specifically with passing a dynamic argument. In the following code, in Test , the last call to M cannot be resolved ( it doesn't compile ). The error is: the call is ambiguous between [the first two overloads of M ] . static void M(Func<int> f) { } static void M(Func<string> f) { } static void M(Func<dynamic> f) { } static dynamic DynamicObject() { return new object(); } static

.Net inheritance and method overloading

我是研究僧i 提交于 2019-12-09 15:12:01
问题 Here is a code sample: class Program { static void Main(string[] args) { var obj = new DerivedClass(); obj.SomeMethod(5); } } class BaseClass { internal void SomeMethod(int a) { } } class DerivedClass : BaseClass { internal void SomeMethod(long a) { } } Can somebody explain me why is a method from derived class called (instead of base class method)? I need a detailed explanation for this situation. I will be grateful for links to any useful articles. Thanks. 回答1: The precise wording and

Type overloading macro

我怕爱的太早我们不能终老 提交于 2019-12-09 12:15:52
问题 I have a bunch of printf debug helper macros and it would be pretty cool to have to not specify the type, is there anything you can do to allow something like macro overloading in c(can be gcc specific if its available in gcc 4.3). I thought maybe typeof but apparently that doesn't work. example macro(I also have some ascii terminal color stuff that I can't remember of the top of my head) #ifdef _DEBUG #define DPRINT_INT(x) printf("int %s is equal to %i at line %i",#x,x,__LINE__); . . . #else

possible to overload function in matlab class?

女生的网名这么多〃 提交于 2019-12-09 11:20:28
问题 Is it possible to overload a function in a Matlab class that you've created? Like the following: function [ sigma_nc ] = sustained_interference( N ) sustained_interference( N, N.center_freq); end function [ sigma_nc ] = sustained_interference( N, center_freq ) ... end Unfortunately when I try this, I get a redefinition error 回答1: If you create the function using the latter, then you can pass it just a single parameter which will be interpreted as the first. If you want default values, then