7,000 questions
1
vote
0
answers
37
views
Implementing errors within overloaded function as a type [duplicate]
I've got a really confusing error, when I tried to implement overloaded functions as a type instead of regular functions syntax.
Here is the code:
function date(value: string, format: 'numeric'): ...
7
votes
2
answers
731
views
Infer argument type of an overloaded function
Assuming two overloads:
void X::f(int, float);
void X::f(long, double);
is it possible, in C++17 or higher, to infer int/long (or whatever it is) from float/double for the second argument?
To be used ...
4
votes
0
answers
166
views
Weird differences between compilers regarding SFINAE and overload resolution
Here's a snippet that does not depend on any external includes, and behaves differently on msvc/gcc/clang.
I left two alternatives inside main.
It compiles with gcc on both alternatives; does not ...
3
votes
1
answer
66
views
Typescript method overload lost
I'm using typescript in a project which uses BackboneJS and in a certain case, a method overload gets lost.
I narrowed it down to this case:
class Model {
set<A extends string>(key: A, value: ...
0
votes
0
answers
87
views
JWT Sign Overloading error with typescript [duplicate]
Getting the following error when i am trying to sign in with my jwt.
No overload matches this call.
Overload 1 of 5, '(payload: string | object | Buffer<ArrayBufferLike>, secretOrPrivateKey: ...
0
votes
0
answers
35
views
How does typescript compatibility check work?
I'm new to both stackoverflow & typescript and I'm quite confused about the concept of compatibility check in function overloading of typescript.
function foo<A, B>(fn: (a: A, b: B) => A, ...
-4
votes
1
answer
174
views
Why am I getting "nan" when I try to overload the modulo operator in C++? [closed]
I am trying to overload the % operator in C++ to make it do division instead of modulo. For example, 5 % 4 should give me 1.25 after overloading.
But I get "nan". Why?
This is the code I ...
0
votes
1
answer
130
views
singledispatchmethod for different list types (e.g. list[str] or list[int])
I'm trying to overload a method with singledispatchmethod. It works great for simple types like int and str, but for different types of nested lists like list[int] or list[str], this breaks with the ...
0
votes
2
answers
110
views
How to extend fixture from the base class?
I'm trying to extend a fixture: that means not only overriding, but partially reusing the old one. For example, in the code below the fixture Test.values uses the fixture values and concatenates lists ...
19
votes
2
answers
1k
views
Why are disabled overloads required to be unique?
The following class has four overloads of function f. When T!=int, all overloads have unique parameter lists, but when T=int, all overloads have the same parameter lists. To make it compile even when ...
-3
votes
1
answer
75
views
Why is a parent class method calling the overloaded child method
I have a general parent class
class Sensor():
def writeCarac(self,uuid,PAYLOAD=None):
pass
def OTAReset(self):
self.writeCarac(0x1234,[1,2,3,4])
and a child class
class ...
4
votes
1
answer
167
views
C++ detecting function overload without conversions
I've have a load of function overloads, mainly consisting of two signatures:
void func(const my_type1&);
void func(const my_type2&, hash_t);
and a function that tries to call func based on ...
1
vote
1
answer
98
views
Procedure Overloading with an allocatable variable as parameter in fortran
I am learning oop in Fortran. And I wonder about the interest of overloading type bound procedure when the type of an argument is not known at compile time.
Let me explain, step by step my problem (...
4
votes
1
answer
116
views
Error using ternary operator and method overloading of wrapper class in Java 8 only
I am using Java 8 and facing some weird error.
The compiler gives the following error:
error: reference to [method] is ambiguous
Here's my code
StringBuilder sb = new StringBuilder();
Stack<...
2
votes
1
answer
87
views
Lambda compatible with two functional interfaces does not give ambiguous method call error on overloaded method, why not?
My overload method is overloaded with 4 different functional interfaces. I have 3 examples in which I call this overloaded method with a lambda that is compatible with 2 of those functional interfaces....
1
vote
1
answer
101
views
F# testing using mstest cannot resolve method overload
As a learning exercise, I'm trying to test some F# code using MSTEST. I've run into a problem that is driving me crazy, not because I can't work around it, but because I don't understand how to ...
0
votes
0
answers
73
views
Why is C# calling this overload instead of a more specific one (maybe override related)? [duplicate]
I have this code, the parent class has an abstract bool Filter(EntityComponent entity) but in this class, I prefer implementing bool Filter(BaseComponent entity) because others are calling the latter ...
0
votes
1
answer
86
views
Typescript function overload with generics doesn't work as expected
I'm trying to create a function that connects to the database and queries for car details. I need the function to have 3 overloads, the first overload returns the basic car details that exist in the ...
2
votes
2
answers
141
views
Simple string.Split failing with StringSplitOptions.TrimEntries
This returns an array with only one element and thus throws an exception. But it works when I omit StringSplitOptions.TrimEntries.
using System;
public class Program
{
public ...
2
votes
2
answers
155
views
How to call std::max() with a size_t expression and a size_t literal constant? [duplicate]
Is there a std::max() overload or a simple way to clamp a size_t expression to a size_t constant, without doing static_cast<size_t>(10) ? The call below does not compile because 10 is not a ...
1
vote
0
answers
120
views
Inheriting from NamedTuple causes "Overloaded function signatures 1 and 2 overlap with incompatible return types" in mypy
I think this is a bug in mypy but I'm not sure:
from typing import overload, NamedTuple
class A(NamedTuple):
pass
class B(NamedTuple):
pass
@overload
def frobnicate(arg: A) -> A: ...
@...
1
vote
1
answer
112
views
Is there a way to disambiguate overloads wrapping std::format and std::vformat
First of all, some demo code:
#include <format>
#include <iostream>
// OVERLOAD 1
template <typename... Ts>
inline void write(const std::format_string<Ts...> &fmtStr, Ts &...
-2
votes
1
answer
99
views
How to overload a function for fixed-size integers and implementation-defined size integers without templates?
I want to write a function of one argument with multiple overloads for different integer types. It want to be able to call it both with types of implementation-defined size (signed char, shot, int, ...
11
votes
1
answer
556
views
Why do std::vector<T> v{1, 2, 3} and std::vector<T> v = {1, 2, 3} call different constructors, when T implicitly converts from int?
Question- see Compiler Explorer
If I create an std::vector<int> and initialize it two ways, both call the std::initializer_list constructor.
std::vector<int> v1{1, 2, 3}; // Calls ...
2
votes
2
answers
93
views
How to get a python function to work on an np.array or a float, with conditional logic
I have a function that I'd like to take numpy arrays or floats as input. I want to keep doing an operation until some measure of error is less than a threshold.
A simple example would be the ...
0
votes
1
answer
283
views
built-in operator '<<' cannot be applied to an operand of type 'std::ostream' [closed]
I'm trying to build a matrix class using a template. I understand that for operator<< to work, it needs to be declared outside of the class, and then declared as a friend function.
When I do ...
0
votes
0
answers
85
views
Compilation issue with subscript operator overloading when another conversion operator is added [duplicate]
The following piece of code compiles fine
#include <iostream>
#include <map>
#include <memory>
using namespace std;
class child {
public:
child(std::string name,uint32_t ...
1
vote
0
answers
44
views
Template-template function overloading ambiguity error using gcc
I have this code perfectly working on clang
template <template <typename, typename> typename T>
struct CollectIntoAllocatedContainer
{
// ...
};
template <template <typename, ...
2
votes
1
answer
61
views
compilation issues with sc_dt::sc_biguint data types (systemc)
I'm facing an compilation issues with sc_dt::sc_biguint data types. I tried to reproduce the issue with a simple example below
#include<iostream>
#include<systemc.h>
using namespace std;
...
4
votes
1
answer
255
views
Is this a false positive [override] error? "Signature of (method) incompatible with supertype"
Although the method signature in Sub is compatible with Super, mypy rejects the override: Signature of "method" incompatible with supertype "Super".
I'm using
python 3.13.1
mypy 1....
0
votes
0
answers
71
views
Explicitly call an overloaded method
I have an inheritance chain:
class Base {};
class Derived : public Base {};
In my interface, I define methods with the same name taking each one of the above classes:
class Interface {
public:
...
0
votes
0
answers
72
views
Error compiling test program using fluent-bit API with fluent-bit.h and g++ compiler
Fluent-bit is compiled under linux (Ubuntu 24.04 LTS) from source (tag v3.2.2)
Using a C-compiler (gcc) test program compiles fine
Using g++ I get compile errors from mpack.h complaining about ...
0
votes
1
answer
46
views
How can I fix the typescript handles function overloading and type inference
I have this playground and I want to make it works in my case.
type Person = {
name: string;
surname: string;
}
type User = Person & {
username: string;
}
type Name = string;
function ...
1
vote
1
answer
46
views
Typescript Function Overload Parameters
I am trying to create a function overload for an API call with a delete method. Here's what I have so far:
type ApiCore = { endpoint: string; key: string };
export type ApiParams = {
routeParam?: ...
1
vote
1
answer
77
views
How do I disambiguate a member function from a member function template
I need to pass pointers to member functions as parameters to other functions. I use std::mem_fn to wrap those in function objects.
Sometimes the member functions have overloads. I learned two syntax ...
0
votes
1
answer
100
views
Is it bad idea to add new functions into an existing 3rd party library's namespace?
My code is using a library called "tf2" and it has a namespace of tf2 and overloaded functions like tf2:fromMsg().
Then in my code, I would like to add one more overloaded function tf2:...
-4
votes
1
answer
93
views
Overload operator += for customString. How to right realization? [closed]
My realization have program then I try to += with empty initial string. I have the empty constructor = default.
Before I try something like:
str = "";
sz = 0;
This is also don't work.
My ...
0
votes
1
answer
418
views
Add custom overload to Python method with existing type hints
Is it possible to extend existing type hints for a Python package in my application code (i.e., not touching the upstream type hints) by adding custom overload for a method? (See also repo with ...
0
votes
0
answers
32
views
How to annotate zipping of dictionaries of differnt ypes? [duplicate]
I want to zip dictionaries into keys to tuples of values. I would be happy to annotate only for specific number of arguments, I will only use up to 5 ever.
from typing import Optional, Tuple, overload,...
5
votes
3
answers
163
views
std::function can't pick between overloads with polymorphic argument type
The following functions have all a different signature. I would expect the functions which have a callable which again has a Base& and one that has a Derived& to be different. Although they ...
1
vote
3
answers
168
views
Ignore the use of a C++ function during compilation having operator<<
I'm developing an API looking like GLib logging.
My API can also disable these functions when the flag -DDEBUG isn't passed to GCC.
That means, there are no residues in the binary, all these debug ...
0
votes
1
answer
80
views
How to force call non-the best match method if multiple methods matched in java
I knew that java will call the best match method if there are multiple methods matched. Refer to the code below, is it possible to force call non-the best match method without modifying method ...
1
vote
2
answers
39
views
Is there way to add one more argument to the function(which has var args) with default value without breaking existing calls?
I have a function
fun foo(
id: String,
vararg values: Int,
){
...
}
and there are calls like these
fun bar1(){
foo("id_1")
foo("id_2", 1)
foo("id_3&...
-1
votes
1
answer
134
views
Function overloading between suspend and non-suspend function is not possible in Kotlin [closed]
I want to provide synchronous version of my asynchronous function, but I can't over load, the function have structure like this. Who can explain, why I can't, and is there any other way to overload ...
1
vote
1
answer
131
views
C++ function parameter overload with parent-child arguments [closed]
I am working on a C++ project involving class inheritance and function parameter overloading. I have two base classes that should never be instantiated but only inherited (by design choice):
#include &...
0
votes
0
answers
66
views
C# string extension methods with same name based on syntax
I would like to compare 2 strings, with syntax either ^([A-Z]\d{2}![A-Z]{2}\d|[A-Z]{3})$ or ^\d{3}$ respectively for both strings with 2 different extension methods but with an identical name IsHigher(...
0
votes
1
answer
98
views
Is it possible to invoke a different version of an overloaded class operator based on whether the call is made from inside or outside the class?
I am developing quite a large Class whose objects require relatively costly validation if they are created by the public constructors, but for which the validation can be dispensed with for private ...
0
votes
1
answer
112
views
Class that inherits from sf::Drawable cannot be use with std::vector
I use the SFML graphic framework to make a very small 2D game engine. Recently, I tried to convert the engine from a static library to a dynamic library, but a problem occurs.
It seems like a class ...
0
votes
0
answers
74
views
Overload resolution of const and non-const function fails on template [duplicate]
In the following code, when calling arr.begin() on a const Array<10> object, it fails to find the const function Accessor::begin() const, and instead only tries MutableAccessor::begin() and ...
1
vote
2
answers
104
views
How to overload Makefile rules?
I have a list of header files which I want to compile at once using Makefile. Some of them, however, have an externally defined function in assembly. If that is the case, there is a file with the same ...