Skip to main content
3 votes
2 answers
105 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>); ...
Michael Deom's user avatar
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: ...
yes's user avatar
  • 19
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 ...
LeDYoM's user avatar
  • 999
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 ...
mdirks's user avatar
  • 73
1 vote
0 answers
179 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....
dallin's user avatar
  • 9,514
0 votes
2 answers
55 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; ...
koolest's user avatar
1 vote
1 answer
96 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>...
Astor's user avatar
  • 394
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); ...
Emre Erdog's user avatar
3 votes
1 answer
167 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 ...
Dr. Gut's user avatar
  • 3,205
0 votes
1 answer
48 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 ...
Steven Osi's user avatar
1 vote
2 answers
165 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 ...
Bartłomiej Konecki's user avatar
3 votes
2 answers
930 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....
CraneStyle's user avatar
0 votes
0 answers
28 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 ...
Annika's user avatar
  • 1
1 vote
2 answers
737 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 ...
D V's user avatar
  • 416
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 ...
sodiumnitrate's user avatar

15 30 50 per page
1
2 3 4 5
16