Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
82 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
58 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
  • 980
1 vote
0 answers
49 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
171 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,386
0 votes
2 answers
48 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
90 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
160 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
156 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
  • 2,826
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
155 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
2 votes
2 answers
540 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
446 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
  • 366
0 votes
1 answer
672 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
1 vote
1 answer
53 views

abstract constructors or equivalent in kotlin

I have some code for a abstract Binary Tree class with nodes. I have an add(value : N) method and and add(value : E)that just takes an element and automatically creates the Node. As you can see below ...
Luke Abruzese's user avatar
0 votes
0 answers
30 views

Python: Change behaviour of [] list instatiation/comprehension [duplicate]

I am working on a solo project and I find myself using very often the following: list_obj = list(map(func, list_obj)) I want to just add the map functionality to the list class to avoid bloat and ...
George's user avatar
  • 135
-1 votes
1 answer
83 views

Do I need to overload the constructor | factory method for each combination of constructor's | factory method's arguments?

I have 4 instance variables that can be initialized by default, is the code written below appropriate? The number of constructors is growing a terrible pace, will I use the Builder object that have ...
Gor Madatyan's user avatar
0 votes
1 answer
607 views

Default constructor with all parameters given default values?

I was reading the book by Joyce Farell on C++, and it's saying that a default constructor is the one with no arguments. I understood it without any hiccups. But things started getting worse after it ...
CREATIVITY Unleashed's user avatar
0 votes
1 answer
220 views

Constructor parameter with byte, short and int throwing error

I am trying to implement constructor overloading by using byte, short and long together. I am passing three values from main method and want to check which constructor gets called Test(byte, short, ...
user9342976's user avatar
1 vote
2 answers
414 views

Constructor parameter with int and long or double and float throwing error

I am trying to implement constructor overloading by using int and long together and double and float together. I am passing two int values from main method and want to check which constructor gets ...
user9342976's user avatar
2 votes
2 answers
152 views

F# Add multiple constructor overloads that call the base class constructor

I'm trying to create a dictionary with structural equality in F# and I want to pass through several dictionary constructor overloads. In C# this would look like class StructuralDictionary<Key, ...
farlee2121's user avatar
  • 3,277
2 votes
2 answers
139 views

Error: A delegating constructor cannot have other mem-initializers

I have the class as follows: class A{ private: int a; int b; int c; public: A(int a1){ a1 >= 0 ? a = a1 : a = -1; } A(int a1, int b1, int c1) : A{ a1 }, b{ b1 }, c{ ...
user avatar
4 votes
0 answers
47 views

Inside of `__new__`, why is `cls` required instead of `args[0]`? [duplicate]

I have two almost identical implementations of the __new__ method for a class. However, in one case, there is an error message. In the other case, it works fine. class Klass1(): # causes ...
Toothpick Anemone's user avatar
1 vote
1 answer
1k views

ShortCut for showing all the constructor overloads in Visual Studio 2022

What is the way to show all the overloads of a constructor in C++ in Visual Studio 2022? Suppose I have a Rectangle class, and I have 3 overloads for them. When I hover my mouse in any of them, ...
Rubayat26's user avatar
  • 117
-2 votes
2 answers
86 views

Using two constructors on one object

I have a User class that has two constructors. When I create an object and use the two constructors, one of them gives me an error saying: no match for call to '(User) (double&, double&, ...
Rosan Syal's user avatar
2 votes
2 answers
128 views

How do we call Base class Constructor from Derived Class using delegating Constructors

I know and I have read many threads to call a base class constructor from a Derived class, But I wanted to implement it using Delegating constructors Here is my code The error states "A ...
Shivang Mathur's user avatar
4 votes
4 answers
109 views

How to call the base constructor of an object from overloaded varargs constructor?

I have a simple class with a constructor of all available fields and i want to add an overloaded constructor with varargs to allow the creating of objects even if some fields are unknown. class ...
wannaBeDev's user avatar
1 vote
1 answer
67 views

Why is the universal T&& constructor called when another constructor is more specific?

In the following snippet I have reconstructed a small failing example of what I'm working on right now. The class entity should be able to gobble up different "functor" types, hence it has ...
glades's user avatar
  • 4,660
1 vote
1 answer
129 views

Typescript arrow functions overloads error 2322

This code below is working fine, but it gives an error for the resolve constant. const resolve: Resolve Type '(param: "case 1" | "case 2" | "case 3") => boolean | &...
Yacine's user avatar
  • 743
0 votes
2 answers
342 views

why we can't use multiple this() in Constructor Overloading?

i'm newbie in this world currently i'm learning java and i wanna to know why i can't use multiple this() in a constructor someone can tell me why please? public class Student { private String ...
Ayoub Bentameur's user avatar
-2 votes
1 answer
567 views

Why does pybind fail for functions without arguments?

I have an overloaded constructor in C++ (default + other). My automatically generated pybind code looks like this: py::class_<MyClass>(m, "MyClass") .def( py::...
thzu's user avatar
  • 53
1 vote
1 answer
84 views

Which Constructor takes precedence when there are two matches for a Generic Class's Constructor

What determines which constructor is used if a Generic class has 2 constructors: One takes (T data), and another (string errorMessage). And an instance is created with type string? For me it seems to ...
Feargal Kavanagh's user avatar
0 votes
0 answers
36 views

New to C++ constructors : why is the output of this program 1 2 and not 1 0 2 0 [duplicate]

why is the constructor Number() not being invoked when a number data type is initialized without any values ? #include <iostream> using namespace std; class Number { int n; public: ...
user19811991's user avatar
2 votes
1 answer
207 views

initializer_list constructor somehow excluded from std::variant constructor overload set

Help me solve this puzzle: In the following code I have an std::variant which forward declares a struct proxy which derives from this variant. This struct is only used because recursive using ...
glades's user avatar
  • 4,660
1 vote
1 answer
292 views

C++ using placement new causes segmentation fault in constructor

please find below code. In this code, when I use "placement new", the I see segmentation fault in constructor, I am not sure why it is causing this, since I can create normal objects. Also, ...
Coder's user avatar
  • 843
0 votes
3 answers
170 views

Is it possible to have constructor with the same number of variables and data type? [duplicate]

I just want to know if we can use overloading constructor with the same number of variables, same data types with the different variables. Employee(String firstName, String lastName, String jobRole){ ...
filocoderist's user avatar
0 votes
2 answers
5k views

Python function overloading recommended approach

Assume a function that takes an object as parameter. There could be various ways to express the parameter object creation, some of which expressive, and likely easier to be used. To give a simple ...
Mukesh C's user avatar
  • 123
0 votes
2 answers
81 views

object constructed as one base class, method calculated as other base class (diamond inheritance and code redundancy)

I have a diamond inheritance scheme in C++ solved through virtual inheritance. The base class is general has two attributes and some method using them. class general { double attr1, attr2; public: ...
Rafael's user avatar
  • 129
1 vote
1 answer
171 views

Deduction guide based on number of parameters passed to constructor

Here's something I'm trying that doesn't seem to work: I want to toggle a compile time switch based on how a class object is instantiated. If there's just one constructor argument, the LengthOpt ...
glades's user avatar
  • 4,660
1 vote
1 answer
364 views

Constructor Chaining with subclasses in Java

Just a question RE: Constructor Chaining in subclasses that I can't find a good answer on and I'm confusing myself a bit with. I'm making a basic little Text Based RPG for some practice and I'm going ...
Conor Timlin's user avatar
0 votes
0 answers
19 views

Overload Resolution with Deleted Constructor C++ [duplicate]

I'm sure this question exists elsewhere, but can't find an answer. I've noticed that when a constructor is defined as deleted, it makes that type take part in overload resolution. In other words, if ...
Robert's user avatar
  • 515
-1 votes
1 answer
45 views

Python programming to remove certain characters from certain positions in a string

Question: s= "campaign_5Nu_E_0_87872_shard1.zip" desired output: campaign5Nu_E_0_87872shard1.zip Guys help me........
Sneha Rani's user avatar
0 votes
1 answer
69 views

How do I make sure all these constructors are called?

This is about c# constructors and has been asked before a couple of times. However, the questions and answers never really fit my scenario: public abstract class BaseClass { public List<int>...
Ingmar's user avatar
  • 1,427
0 votes
2 answers
299 views

Copy Constructor vs Assignment Operator Overload in the dynamic array class in C++

We made a dynamic array class during lecture and the instructor copy-pasted the copy_constructor code on the assignment_operator_overload. But don't we need to delete the existing dynamic array first ...
VoidRust's user avatar
0 votes
1 answer
572 views

Generic constructor template called instead of copy/move constructor

I've designed a simpler wrapper class that adds a label to an object, with the intent of being implicitly convertible/able to replace the wrapped object. #include <string> #include <...
joaocandre's user avatar
  • 1,735
1 vote
1 answer
74 views

How to provoke a compile-time error if a specific overload of a function is called?

According to https://en.cppreference.com/w/cpp/string/basic_string_view/basic_string_view, std::basic_string_view class has 7 overloaded ctors. I only care about 2 of them since right now I don't use ...
digito_evo's user avatar
  • 3,652
1 vote
2 answers
460 views

C++ N-API Multiple Type Signatures

I am learning C++ and playing around with OpenCV and node-addon-api. I wanted to create my own wrapper for cv::Vec. docs #include <napi.h> #include <opencv2/core/matx.hpp> class Vec : ...
Michal's user avatar
  • 5,220
20 votes
1 answer
1k views

Why doesn't std::string have a constructor that directly takes std::string_view?

To allow std::string construction from std::string_viewthere is a template constructor template<class T> explicit basic_string(const T& t, const Allocator& alloc = Allocator()); which ...
oliora's user avatar
  • 899
0 votes
4 answers
419 views

How to use if else statement in java constructor

I am trying to overload a constructor in java. There are two Strings among its variables which is problematic if I write two separate constructors in the case of only one of these strings being called....
user avatar
0 votes
2 answers
117 views

Can an overloaded member function of a class depend on the outcome of an overloaded constructor of that class?

I have a class with an overloaded constructor where each version of the constructor initializes a different set of private attributes for that class. I also have a public member function of that class ...
drakon101's user avatar
  • 536

1
2 3 4 5