Skip to main content

Questions tagged [constructor]

A special type of subroutine called at the creation of an object.

constructor
-1 votes
0 answers
42 views

Is it possible to have a constructor with multiple parameters, only to use few of the possible parameters on initialization? [duplicate]

In other words, is it possible to use only few parameter on initialization of a class, even when the constructor has multiple parameters? Or is there a way to do so, without having to make a ...
user16393738's user avatar
1 vote
1 answer
28 views

initializing inline and initializing inside constructor which does run first in Typescript?

I'm learning about class concept in typescript. I recognize that there are two ways to initialize fields (properties) in typescript: initializing inline the class body and initializing inside the ...
LeoPkm2-1's user avatar
1 vote
0 answers
20 views

PHP 7.4 is ignoring incorrect parameter passing [duplicate]

I have the following class with the following constructor: class Film { private string $name; private int $releaseYear; private string $genre; private array $notes = []; public ...
Pedro Schinke's user avatar
0 votes
1 answer
21 views

How to do self-contained Lazy Initialization using async/await

I am trying to initialize a class asynchronously using dependency injection. I have seen this article https://blog.stephencleary.com/2013/01/async-oop-2-constructors.html but I am trying to initialize ...
Nick Tucker's user avatar
2 votes
1 answer
86 views

How to return smart pointers and covariance in C++

I am following this tutorial to understand how to return smart pointers and covariance in C++. #include <memory> #include <iostream> class cloneable { public: virtual ~...
GPrathap's user avatar
  • 7,650
3 votes
1 answer
49 views

Multiple constructors annotated with Lombok @Builder cause a problem?

This is my first question, so please feel free to correct anything that I missed writing this question:) I am having trouble with using the @Bulider with my DTO objects. I have an abstract class "...
Doh Kun Lee sanity's user avatar
-1 votes
0 answers
26 views

How to solve the following problem for method where we have other [closed]

Question: A point represents a location in a two-dimensional space, characterized by its x and y coordinates. Here is the partially completed Point class that you will be working with: class Point: ...
Pratap M Naik's user avatar
-2 votes
0 answers
55 views

a constructer declared in a type with parametere list must have 'this' constructor inisializer error [closed]

I'm working on a C# project where I have an abstract base class Employee with a parameterized constructor Employee(string name). My derived class FullTimeEmployee has a constructor that takes three ...
Smoker's user avatar
  • 1
0 votes
1 answer
82 views

Copy constructor and creation of temporary object C++ [closed]

Let me use as example a vector object but it applies to any object. Is it safe to create an object as MyVector xyz(std::vector<double>(10)); assuming that there is a constructor which take as ...
Albert's user avatar
  • 11
5 votes
3 answers
170 views

Initialization order of inherited constructors

I have this example: #include <iostream> #define print(X) std::cout << X << std::endl struct B1 { B1(int _i = 5): i(_i) { print("B1 constructor"); }; int i; }; ...
mada's user avatar
  • 1,932
-2 votes
0 answers
13 views

Why constructor cannot access static variable inside the constructor block?

Why static variable can't be accessed using this keyword inside a constructor I created a static variable and a no argument constructor inside a class when I try access the static variable with the ...
Yogi's user avatar
  • 1
-3 votes
0 answers
54 views

Why java is not giving me default constructor [duplicate]

package com.vedantkakade; class Student { String fname; String lname; public void printInfo() { System.out.println(fname + " " + lname); } Student(Student ...
Vedant Kakade's user avatar
0 votes
2 answers
76 views

Use of deleted function std::unique_ptr<_Tp, _Dp>& std::unique_ptr<_Tp, _Dp>::operator=(const std::unique_ptr<_Tp, _Dp>&)

I am currently trying to set up a very basic Entity Component System. For this, I have defined the following classes: class Component { public: virtual ~Component() {}; // Ensure polymorphic ...
notfynnaf's user avatar
0 votes
0 answers
51 views

I was trying to create class mystack which would work like a stack datatype but i encountered unexpected output

This is the code where i tried to implement stack in c++ without pointer instead i used a interger variable called "top" to hold the current position of stack and also i created constuctor ...
Dushyanth Yadav v's user avatar
-1 votes
0 answers
56 views

Compiler misidentifying/unrecognising type [duplicate]

I have the following class with constructor: command.h: #include "./robots.h" enum class CMD { //...... }; class CommandTemplate { //..... public: virtual std::unique_ptr<...
steve89's user avatar

15 30 50 per page
1
2 3 4 5
1410