230 questions
3 votes
2 answers
106 views
Disambiguating ambiguous function overloads because of converting constructor
Given a wrapper type template <typename T> struct Ptr { Ptr(T*); }; a class hierarchy struct Base {}; struct Derived : Base {}; and a set of function overloads void f(Ptr<Base>); ...
1 vote
1 answer
98 views
How to check what constructor overload is used
If I have a class constructor with two overloads taking in different inputs, is there a way to tell them apart? For example, class example { double ExampleDouble; char ExampleChar; public: ...
0 votes
0 answers
63 views
Should a constructor with a std::initializer_list be explicit?
I am designing a container (yeah, do not reinvent the wheel, I know). Let's call it Container<T>. I have a constructor to allow the initial number of elements: explicit Container(std::size_t ...
1 vote
0 answers
51 views
CS0121 Ambiguous Call with Collection Initializer [duplicate]
I'm on a team with two other devs. For the past few months I've been working on a project in C# 12 independently, and only recently have the other devs pulled my code and run it. For one of them it ...
1 vote
0 answers
183 views
How can I overload a constructor in a private nested class without getting a "Resource Not Found" error when I call Inherited Create?
I have a Managed Record named TEmail with a nested private class called TEmailForm that inherits from TForm. The idea is my email Record can create a modal form as needed for the user to type an email....
0 votes
2 answers
56 views
How can I call constructor with less parameters with no assignment of default value to a class variable in Java?
public class Sample { int id; String name; int age; Sample(int i, String n){ id = i; name = n; } Sample(int i, String n, int a){ id = i; ...
1 vote
1 answer
99 views
Deduce member size from initialization list in constructor (CWG 1591) What's the right way? [duplicate]
I have a class Vec<C> that works as below, and I need to know a way to write the constructor and/or deduction guide such that a braced-enclosed initializer list deduces C as std::array<T,N>...
2 votes
3 answers
164 views
Two identical constructors however compiler selects the templated one
I am trying to implement a list container in C++, and I have problem with compiler selecting the wrong constructor overload. The constructors are as follows: list(size_type count, const T& value); ...
3 votes
1 answer
169 views
Inheriting constructors and forwarding reference
Consider the following two classes: struct Base { Base() = default; Base(auto&&); }; struct Derived : Base { using Base::Base; }; If I try the following test with Type = Base and ...
0 votes
1 answer
55 views
Overloaded function not outputting correct answer
I am attempting to create an overloaded contructor that will take in integer and add them with the byteAdd function. However; whenever I compile the output is always the default constructor rather ...
1 vote
2 answers
169 views
How to make compiler differentiate f(double...) and f(int, double...)
I am writing a small library for working with polynomials. The main class is called poly and it contains 4 overloaded constructors. An object of class poly is a representation of one polynomial. Full ...
3 votes
2 answers
963 views
OOP Python Overloading the '__init__' method
I am porting a project from Java to Python and there is a class with multiple constructors. I'm trying to port that same idea to python, in a pythonic way. I've recently been informed of the typing....
0 votes
0 answers
31 views
how can i limit the user to a certain input [duplicate]
Hi I'm trying to learn java This a simple program that stores a patient's blood details, well in any case how can i keep the program accurate by means of returning an error message if the input was ...
1 vote
2 answers
760 views
Class constructor overloading in Typescript
I am working on a class PlaybackControl, I use it to create two HTMLElements: PlaybackControlButton: HTMLButtonElement PlaybackControlMenu: HTMLDivElement Now, to initialise the class object, I need ...
1 vote
1 answer
1k views
Can I overload init from C++ side in pybind11?
If in C++ a class had an overloaded constructor: class MyClass { std::string name; public: MyClass(){}; MyClass(std::string name_){ name = name_;} }; how do I expose this to python? Can I ...