Questions tagged [constructor]
A special type of subroutine called at the creation of an object.
constructor
21,141
questions
-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 ...
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 ...
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 ...
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 ...
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 ~...
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 "...
-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:
...
-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 ...
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 ...
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;
};
...
-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 ...
-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 ...
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 ...
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 ...
-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<...