Questions tagged [overloading]

A type of polymorphism where different functions with the same name or different implementations of an operator are invoked based on the data types of the parameters passed. DO NOT USE FOR OVERLOADING IN PHP; THE MEANING OF THAT TERM IN PHP IS UNRELATED.

Filter by
Sorted by
Tagged with
2 votes
2 answers
63 views

In nim is there a way to get a list of all procedures with a given name?

In Nim is there a way to get a list of the declarations of all procedures with a given name which are defined at a given point in the code? For example I am looking for a function TYPE where following ...
Nate Ackerman's user avatar
-2 votes
0 answers
30 views

How to overload(override) cin operator >>? [duplicate]

I want to design that something particular character entered, console output "good" string x int y cin>>x cin>>y in this program, if (x and y are all) == "0", i want to ...
이웅기's user avatar
-2 votes
0 answers
63 views

Overload resolution not working with function template

The following code: #include <iostream> #include <utility> using namespace std; #define pair_t std::pair<uint64_t, size_t> constexpr pair_t bit_concat_rev_(pair_t v) { return v;...
Aries Victor's user avatar
0 votes
0 answers
30 views

Why am I getting this error? (Typescript + Express)

I am getting this error: No overload matches this call. The last overload gave the following error. Argument of type '(req: Request, res: Response) => void' is not assignable to parameter of ...
Yigit Gulay's user avatar
5 votes
2 answers
190 views

Fooling R's Method Dispatch

I am looking for an example where a dot in a function name causes R's Method Dispatch to pick the wrong function. A natural candidate seems to be the builtin function t.test(), which should be ...
cdalitz's user avatar
  • 1,131
1 vote
3 answers
179 views

How to "merge" 2 functions (const & non-const i/o) into one?

Is there a syntax for merging the following 2 functions into one, so that if input is const, result is const, and if input is non-const, result is non-const? char* f1(char* x) { return x+1; } ...
Sasha's user avatar
  • 339
-1 votes
0 answers
95 views

Overload 'call by value ' and 'call by reference' function? [duplicate]

I would like to define a single name 'f' for a function with two overloads, one is 'call by value', the other 'call by reference' #include <iostream> using namespace std; int f (int a) { ...
Gabriel Costa's user avatar
0 votes
0 answers
30 views

Kafka callback issues with overloaded methods in java

We have two micro-services transfer and approval. The request from transfer will be sent to approval and once approved the funds are transferred. During the submission of approval, there is a Kafka ...
Arun Sudhakaran's user avatar
12 votes
3 answers
198 views

Integer parameter calls float overload and float parameter calls integer overload? [duplicate]

Today i ran into roughly the following code: #include <iostream> void f(float&& f) { std::cout << f << "f "; } void f(int&& i) { std::cout << i <&...
user22879756's user avatar
-1 votes
2 answers
63 views

constructor call must be the first statement in a constructor error alternative

I have started learning Java and was trying to write some code. I want to throw an error when box(negative) is called, before calling this constructor, but it shows me this error. constructor call ...
val didar singh's user avatar
-3 votes
0 answers
83 views

How to set std::function with overloaded functions? [duplicate]

Is it possible to assign an overloaded function to an std::function object? #include <algorithm> #include <functional> #include <vector> int Incr(int x) { return x + 1; } int ...
Pietro's user avatar
  • 12.3k
2 votes
2 answers
59 views

Typescript modify type based on generic

Question Is there a way for the generic of a type to modify the type itself? Can it be done without creating two functions? This is not about js functionality, only about getting the types to match. ...
nick zoum's user avatar
  • 7,247
0 votes
0 answers
23 views

Why it's bad that overload a class static method with different arguments [duplicate]

I have Python codes: class A(object): @staticmethod def print(): print('A') class B(A): @staticmethod def print(val): print('B' + str(val)) And I want to use them ...
Rocky.L's user avatar
  • 59
4 votes
4 answers
106 views

Confusion in Overload Resolution

I can't figure out how is overload resolution working here! With the first snippet it resolves to OVERLOAD A but with the second it raises an error "ambiguous call". CODE 1 #include <...
imbot's user avatar
  • 55
1 vote
1 answer
92 views

Is there a way to know at compile time, which version of an overloaded function has been chosen by the compiler to be called?

A possible way of doing this is to make the return type of the overloaded functions store the information of the specific function: template<class _ret_t, class _func_t> struct tpinf { using ...
Aries Victor's user avatar
1 vote
1 answer
83 views

Overloading an overriden method

Is it possible to implement multiple overloaded methods in a derived class that would be called like an overriden method? I couldn't find anything on this topic. Short example: class BaseClass { ...
kallinea rae's user avatar
1 vote
1 answer
70 views

Is it true that overloading must differ in parameter types or number of parameters but not erasure in Java?

Erasure is decided at runtime and overloaded method to call is resolved at compile time. Is it correct to say that overloading must differ in parameter types or number of parameters but not erasure in ...
banan3'14's user avatar
  • 4,102
0 votes
0 answers
37 views

Errors in my code that indicates illegal modifier and syntax error, "VariablesDeclarators"

import java.util.Scanner; public class Rectangle { private static double setLength1 = 0; private static double setWidth1 = 0; public static void main(String[] args){ // TODO ...
E.schneider's user avatar
1 vote
1 answer
62 views

Spark Row object instantiated differently from overloaded prototypes?

The Spark Row class in pyspark/sql/types.py contains no __init__ method, but shows the following overloaded type hints for __new__: @overload def __new__(cls, *args: str) -> "Row" @...
user2153235's user avatar
2 votes
2 answers
61 views

passing member function const and non-const overload to std::function

I was trying to get "more fluent" with function pointer manipulation and I've got an issue with passing a member function to std::function when there are two overload: const and non-const. ...
Oersted's user avatar
  • 1,050
1 vote
2 answers
48 views

Overload template operator of template class that uses SFINAE

I have a template class (with SFINAE condition) and I'd like to overload a template operator << for it. This code works, but it also allow all operator << overloaded for all types T to ...
SNJ's user avatar
  • 183
1 vote
0 answers
30 views

Powershell Parameter set cannot be resolved despite types being unique in each set? [duplicate]

Trying to create a function with a parameter set for overloading usage, originally I have had a pipeline input and desired to truncate the first parameter without specifically mentioning -ScriptBlock ...
Yorai Levi's user avatar
0 votes
1 answer
44 views

How to avoid duplicate optional arguments in overloads?

In C#, I have a function of the form void Foo(Vector<double> v, int k = 1) { ... } where Vector<double> is a type from the MathNet.Numerics.LinearAlgebra package which represents a ...
ummg's user avatar
  • 249
0 votes
1 answer
259 views

Why is there a "No overload matches this call" error when passing a reactive prop?

In my main application I defined import { DateTime } from "luxon" const now = ref(DateTime.now()) const maxCityNameSize = ref(0) The variables are then passed to a component: <time-bar :...
WoJ's user avatar
  • 27.7k
3 votes
2 answers
65 views

Overloading methods for parametrized struct

Short Version I have a struct like @kwdef mutable struct Params{B, C} a::Float64 = 42 end where B and C are symbols that will determine which function to use out of many functions that are ...
Jared Frazier's user avatar
1 vote
1 answer
33 views

Specialize C++11 template based on type traits while allowing fallback for other types

I am currently working on serializing several data structures to JSON. The existing data structures already provide a text-based output format that I want to use as the default when the functions that ...
kmhaug's user avatar
  • 113
1 vote
0 answers
54 views

Python 3.8: @typing.overload usage with typing.Literal and Enum values

According to https://peps.python.org/pep-0586/#legal-parameters-for-literal-at-type-check-time typing.Literal works with Enum values as legal parameters. But autocomplete does not work with following ...
Egor Erofeev's user avatar
0 votes
0 answers
45 views

F# SRTP doesn't work for overloaded methods?

SharpLab My actual use case has nothing to do with DateTime. I want to call multiple overloaded methods defined on a builder struct. They are call path dependent, return a modified this struct. So I ...
nodakai's user avatar
  • 7,823
0 votes
0 answers
55 views

Is there a way to direct the compiler to one overload when there is an ambiguous overload?

#include <cstddef> template<class T> T func(int*){ return T(0); }; int* someptr; template<class T> T func(size_t v) { return func<T>(someptr + v); } int main() { func<...
Apple_Banana's user avatar
0 votes
1 answer
43 views

Get proper intellisense with overloaded multimethods in python

The following code works as expected: from multimethod import multimethod @multimethod def foo(a: int): print(f"only {a}") @multimethod def foo(a: int, b: int): print(f"{a} ...
DaNubCoding's user avatar
3 votes
1 answer
111 views

How to make a wrapper<int> class with a converting constructor win against wrapper<double> in overload resolution?

I'm trying to design a wrapper to tackle arithmetic params with some special logic. https://godbolt.org/z/zG959e5Pz #include <stdio.h> template <class T> struct wrapper { wrapper(...
xujh's user avatar
  • 43
0 votes
0 answers
18 views

calling .net function (IVI.net) with correct type

I am trying to acquire data from an R&S Oscilloscope RTB 2004 using the IVI.net driver. Connection to the oscilloscope is established. I can create an object named "oszi" in the repl or ...
Axel's user avatar
  • 13
0 votes
0 answers
22 views

"This overload signature is not compatible with its implementation signature" error when combining normal and ...rest function parameters

I am trying to create types for my fork of strformat function. This function takes a string, and an optional list of interpolated varibables, defined in one of three ways (each having its overload): ...
Michal Kurz's user avatar
  • 1,692
-1 votes
1 answer
54 views

Understanding Function Overloading Ambiguity in C++: Square of Double vs. Float Argument [duplicate]

Consider the following program, which is based on an example from the Deitel C How to program book. // funOverloading.cpp #include <iostream> using namespace std; // function square for int ...
Osmium's user avatar
  • 177
0 votes
1 answer
33 views

Kotlin overload "-" for type String

I've been trying out Kotlin recently. I now have a task that I'm stuck on. I need to overload the operator "-" for type String. The new function should create a new String out of an existing ...
Paul Schmiel's user avatar
1 vote
1 answer
33 views

C# Reflection and overloaded Methods: Get Method the compiler would have chosen / "Closest Ancestor"

Given this Situation: class Wrapper { class Base {} class A : Base {} interface IA {} class B : A, IA {} void Func(Base param) {} void Func(A param) {} void Code() { ...
final's user avatar
  • 213
1 vote
1 answer
95 views

Function template overloading vs class templates

Function-templates can be overloaded by using different template-parameter-lists (if I interpret https://en.cppreference.com/w/cpp/language/function_template correctly). If the template-parameter-...
wimalopaan's user avatar
  • 5,060
0 votes
1 answer
74 views

Could a char[] be moved into a rvalue?

If I have two overload function like void f1(const char(&)[4]) { std::cout << "f1 lvalue" << std::endl; } void f1(char(&&)[4]) { std::cout << "f1 ...
f1msch's user avatar
  • 579
0 votes
1 answer
66 views

JAVA: Compiler error using ternary operator in method overload

String a = "bla"; byte[] b = new byte [10]; method (a != null ? a : b, b); Why can't I use the above method call using ternary operator? Using if else statement works fine: if (a != null) {...
NotInCheck's user avatar
2 votes
2 answers
82 views

Swift Extension: augment existing class with method overloading

Consider the Logger class from the OSLog framework: Logger Since the OSLog API doesn't allow querying for the information such as the name of the file, the line and the function where the log commands ...
Richard Topchii's user avatar
0 votes
0 answers
20 views

1/5 host is being overloaded when using Apache Http client & Pooling connection manager to interact with the services

We have service A and Service B, B has 5 hosts which is being called using domain name from Service A. MaxTotal is set as 100 and DefaultMaxPerRoute as 50. No keep alive strategy and no explicit close ...
Aswathy's user avatar
0 votes
2 answers
64 views

C++: overloading method with parameters of multiple subclasses

I am making chess, it's a great way to practice basic OOP. There's an abstract base class Piece with subclasses like King, Rook, Pawn, etc. as well as a Board class. Is there a way to create multiple ...
BENJAMIN GILBERT's user avatar
0 votes
1 answer
95 views

How to override anonymous function in JavaScript with Tampermonkey?

I have a function I want to override in an anonymous function with Tampermonkey. (()=>{ /* other stuff */ function Zm(e) { let {visible: t, onCancel: n} = e; const ...
ZeroPhase's user avatar
  • 649
1 vote
2 answers
41 views

Is there a good way here to allow users to both retain access control for properties and overload indexing methods?(matlab 2020a)

Assuming a member within a class has private access properties, i.e., GetAccess=private, if we use a "." type reference for that member in the overloaded subsref method, then the access ...
bokabokaboka's user avatar
0 votes
2 answers
37 views

How to overload A{n} in a custom class? matlab 2020a

Background knowledge subsref Some explanations in the book (published in 2014): When overloading the subsref method, you can use a switch statement to select the type of index and obtain the actual ...
bokabokaboka's user avatar
4 votes
1 answer
147 views

Can I @override the following @overloaded Python function?

The PySide6 function QComboBox.addItem is type-hinted, in QtWidgets.pyi, like this: @overload def addItem(self, icon: Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], text: str, userData: Any = ...) ...
bers's user avatar
  • 4,934
0 votes
0 answers
13 views

JvmName annotation not working for android `ViewModel` with kotlin

I have a ViewModel where I want to have 2 functions with the same signature but different implementation. obviously I got the error "conflicting overloads". I used to be able to solve this ...
or_dvir's user avatar
  • 529
0 votes
1 answer
35 views

Hippomock static function with overload, how to use ExpectCallFuncOverload?

With the following class: class Math { public: static int Add(int a, int b) { return a + b; } static int Add(int a, int b, int c) { return a + b + c; } }; How to use ...
xibi's user avatar
  • 101
0 votes
1 answer
68 views

Aggregate mongodb error : No overload matches this call

Im trying to make an aggregate from mongodb, this is the code : const reports = await FullProfile.aggregate([ { $match: { updatedAt: { $gte: dateFilter.startDate, ...
Lugas Anegah's user avatar
0 votes
3 answers
54 views

error: invalid operands to binary expression ('book' and 'const int') in find in c++

class book{ public: void setNameOfAuthor(string nameOfAuthor); string getNameOfAuthor(); void setBookId(int bookid); int getBookId(); bool operator==(const book& rhs)const; const ...
farida fathima's user avatar

1
2 3 4 5
138