Questions tagged [constructor]
A special type of subroutine called at the creation of an object.
constructor
21,142
questions
-1
votes
0
answers
26
views
When I call the constructor in the main program, the default values are getting displayed. I want the values initialized in the default Constructor() [duplicate]
When I call the constructor in the main program, the default values are displayed. I want the values initialized in the default Constructor(). Why constructor overloading is not happening when I ...
1
vote
1
answer
51
views
C++ overload resolution problem: How to make vector fill constructor overload instead of vector initializer list construtor?
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<char> v1 = { size_t(0),0 };
vector<char*> v2 = { size_t(0),0 };
cout << v1....
-1
votes
0
answers
32
views
Unity C# using "new Color(0,0,0,1) " doesnt do anything in inspector
So basically, as stated in the title. I have a variable set to
[SerializeField] Color textColor = new Color(0,0,0,1);
and it does absolutely nothing in the inspector. I could set that color to ...
-1
votes
0
answers
51
views
Pass collection to constructor from xaml [closed]
I have a problem with passing elements collection to a constructor from xaml. Is there a solution to pass multiple arguments to constructor from xaml?
An example of what I want to achieve:
In c#:
...
-1
votes
0
answers
48
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
29
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
21
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
25
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
2
answers
93
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
51
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 "...
5
votes
3
answers
178
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
55
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 ...