Questions tagged [constructor]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 views

How to pass array as a value in constructor in java [duplicate]

I want to assign values directly to the marks array in the constructor Student. I want to pass the value as Student s1 = new Student(123,"jack sparrow",3, {23.0,40.0,30.0}); is it possible? ...
akharwar's user avatar
-3 votes
0 answers
28 views

A problem of binding in java. Hiding or Overloading problem? what is the output? [closed]

my question is what will be printed and why. Especially , is it a situation of hiding? how does the compiler insure that he can call f() from the consructor of bar, because he sees it as Foo and the f(...
nelad's user avatar
  • 5
0 votes
0 answers
26 views

Why is mockkConstructor() not working on the every block?

I'm trying to mock a constructor of a class that is a lazy variable of the class I'm testing: private val manager by lazy { manager(Data(ID_ADMIN, MANAGER_CODE), context) } I have the mockk() ...
Dave_August's user avatar
-1 votes
0 answers
63 views

Dynamic memory reallocation to create a unlimited integer class [closed]

I have to create a class which can have integer of unlimited length. How should I dynamically reallocate the size of the array which contains each digit of the integer. Is there any way to make the ...
Daksh's user avatar
  • 1
-1 votes
0 answers
18 views

Exception when trying to bind a UFUNCTION with AddDynamic to a Delegate

Added UDP Component plugin (from here: https://github.com/getnamo/UDP-Unreal/tree/master) to my project and now im trying to bind a UFUNCTION HandleReceivedBytes (from my pawn class) to a Delegate ...
syat-cd's user avatar
0 votes
2 answers
41 views

Do the parameters of a constructor in Java have any connection with the properties of the class?

I'm confused... package car; public class Car { private String color; private int maxSpeed; private String brand; public Car(String somethingElse, int maxSpeed, String brand) { ...
Ruben Virtic's user avatar
0 votes
0 answers
6 views

'PointerWrapper' does not contain a constructor that takes 0 arguments

im trying to run a splashkit project but this error keeps popping up and won't let me run the file and gives me this error. Anyone know how to fix this? heres my program.cs using SplashKitSDK; public ...
Scrub Tactics's user avatar
-1 votes
0 answers
33 views

Assertion Failure with Unit Tests

I'm getting this specific error "/usr/include/c++/9/bits/basic_string.h:1052: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_reference std::__cxx11::basic_string<_CharT, ...
TobyFromHR's user avatar
0 votes
1 answer
66 views

Is it ok to initialize final member in abstract base class using abtract method?

I wonder whether I could initialze a final field in an abstract base class with the result of an abtract method, which would be implemented by the derived class. I understand that derived ctor would ...
Y.F.'s user avatar
  • 31
0 votes
1 answer
60 views

Why does C++ class show 2 constructors after I declared only one constructor?

I have the following C++ class: class MyClass { private: PCWSTR _windowName{}; PCWSTR _windowTitle{}; public: MyClass(PCWSTR wndName, PCWSTR wndTitle) { this->_windowName = ...
Yashoja Lakmith's user avatar
-3 votes
0 answers
72 views

I want to ask a question about constructor [closed]

I'm a C++ beginner I wrote a code recently and give it to chat gpt to see what the problem is. This is the code it gave me: #include <iostream> using namespace std; class Animal { public: ...
蔡天意's user avatar
1 vote
1 answer
55 views

Hook construction of objects

I am trying to intercept the construction of all objects. function inheritFrom(){ this.property = 'Example' } let inheritedObject = new inheritFrom() Whenever an object instantiation happens, I ...
RovenA's user avatar
  • 91
0 votes
1 answer
71 views

Why is it that when I call the constructor with Float.MIN_VALUE parameters, they are 0?

So I have a Vector3f class with a constructor: public Vector3f(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } but when I call a constructor like this: ...
notwhale's user avatar
0 votes
0 answers
20 views

The 'bind()' method within a constructor in JavaScript [closed]

Is it a good practice to use .bind(this) in the constructor or it's better to avoid it and istead use arrow function for event handlers to automatically bind 'this' ? Thanks. Example: constructor() { ...
Jamzze's user avatar
  • 1
-2 votes
0 answers
26 views

What does it mean by "call the triangle hypotenuse method" [duplicate]

I don't understand the last few steps of this assignment. I did something similar in a previous assignment and copied the same format but nothing works. I even watched some videos on classes and the ...
5hy's user avatar
  • 1
0 votes
0 answers
10 views

Getting error when trying to mock class method to return value it is call real method

Below is the test class ` @RunWith(Parameterized.class) @SpringBootTest(classes = TelelogServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("...
kee's user avatar
  • 11
-2 votes
1 answer
53 views

class of vector based on std::vector [duplicate]

I want to make my own vector class basing on std::vector. Everything seems to be easy, but I get an error even from the constructor. The class (minimum example) is as follow: #include<vector> ...
Antonella Longo's user avatar
-2 votes
0 answers
26 views

Annotate this member with "@Auto wired", "@Resource", "@Inject", or "@Value", or remove it [closed]

enter image description hereenter image description hereI am getting this error Annotate this member with "@Auto wired", "@Resource", "@Inject", or "@Value", or ...
dheeraj's user avatar
0 votes
0 answers
37 views

Why am I getting the error "declaration is incompatible" with "ArraySet<ItemType>::ArraySet()"? [closed]

My code worked just fine until I added the second constructor, nothing with the other files changed and nothing else references the first or second constructor, so I have no idea what could be causing ...
FiSH's user avatar
  • 19
-1 votes
0 answers
32 views

Python Inheritance not working as intended [closed]

I am new to Python and can't figure out what is happening to the inherited objects. This is a reproducible example of what I am trying to do... class HipHop(object): def __init__(self): ...
Nitin Rattu's user avatar
-1 votes
1 answer
62 views

int OR int() for initialization to zero in C++

A confusion regarding the concept of using parenthesis '( )' in C++. I found out when we use int() it means, we are calling constructor of "int" data type. And in C++, int() initializes ...
AlexG's user avatar
  • 57
1 vote
2 answers
88 views

How to correctly implement an own property getter/setter via Object.defineProperty and utilizing class syntax?

it's my code "use strict"; class Employee { constructor(firstName, lastName, age, salary, gender) { this._firstName = firstName; this._lastName = lastName; this._age = age; ...
Delfon's user avatar
  • 19
-2 votes
1 answer
56 views

C++ variable initializes even though the copy constructor is deleted

The code below works unexpectedly! class CameraBuffer; class CameraBufferAccessor{ friend CameraBuffer; private: CameraBufferAccessor(const int &data, const int &mutex); public: ...
SᴀQɪB M's user avatar
0 votes
0 answers
47 views

How to call two constructors from two derived classes from the base class in a for-loop?

From my base class, I 'm trying to call two class constructors from two derived classes each. I have two derived classes; I'll call them ClassA and ClassB. Both ClassA and ClassB have two derived ...
Takeshi DBXV's user avatar
1 vote
1 answer
61 views

Haskell: Similar data constructors and boiler plate

I have a type constructor Token and all of its data constructor take an Int (the position where this token was encountered in the input) and maybe some payload: data Token = EmptyToken Int -- just ...
Chirmol Studio's user avatar
0 votes
0 answers
11 views

Why a default constructed object in Python contains the data of a previously used other object? [duplicate]

I have a class Foo that takes by default an empty dictionary {} in its __init__() function. I instantiate a first object a and fill its dictionary. Then, I instantiate a second object b, and I was ...
T.L's user avatar
  • 615
0 votes
0 answers
32 views

Flood Fill not drawing to canvas

I have a flood fill algorithm for a drawing application (using p5.js and the editor is brackets), each tool is in its own separate constructor function. I am using javascript and HTML The problem I am ...
Jason Slade's user avatar
0 votes
1 answer
43 views

Pass event handler to object constructor as an argument

I have a method for executing batch scripts in memory by passing along a list of commands and executing them in a new Process. I use this method for running things like psql and gpg commands and it ...
G_Hosa_Phat's user avatar
  • 1,006
0 votes
0 answers
48 views

How does the form designer instantiate the controls in a partial class without instantiating the fields declared in the outer part?

I have a form in Winforms that contains the following code : //MainForm.Designer.cs partial class MainForm { ... private void InitializeComponent() { ... } } //MainForm.cs public ...
tigrou's user avatar
  • 4,226
-4 votes
0 answers
33 views

When is it appropriate to create an object using a constructor vs creating object using "new"? [duplicate]

Noticed a code change that added a method to create a new class object instead of just using the new keyword. Is this a practice that I'm not aware of, or an unnecessary change? //Original code ...
Alex's user avatar
  • 1
0 votes
0 answers
36 views

What does it mean in Java when a method or constructor parameter is preceded by @Json(name="something")?

I came across some code that I am trying to analyze. There is a class that has a constructor that looks something like this: public Thing(@Json(name = "var1") String str, @Json(name = "...
Rikudou's user avatar
  • 155
0 votes
1 answer
19 views

MethodError in Inner Constructor with Vector Input

I'm trying to implement a SparsePolynomial type that stores the terms as items in a linked list (from DataStructures.jl) with a dictionary pointing to items in the linked list. This struct takes input ...
mysterymachine's user avatar
0 votes
1 answer
66 views

Is there any way to call a constructor inside another constructor but in different class?

I have 2 forms namely Form1 and Form2. I want to call Form1's constructor inside Form2's because I want to initialize my Form1 before Form2. //Inside Form2.cs Form1 form1; public Form2() //line1 { ...
Junaid Javed's user avatar
-2 votes
1 answer
39 views

Code was skipped after a instance of JPanel was created

I am making a copy of the game Tetris and have created a game panel. I was trying to swap the order of tetris.initGamePanel(); and tetris.initWindow(); in public static void main(String[] args){ ...
山宗陽成's user avatar
0 votes
1 answer
20 views

Is it possible to access class members by just its class name in dart 3 without making instance of the class? and how?

I am creating a class of strings for my flutter applicaion and I want t make all class members static but problem is I want to prevent making instance of that class and I want to acces its members by ...
Huzaifa Zameer's user avatar
-1 votes
3 answers
91 views

How to create a constructor without repeating yourself?

Consider the following TypeScript classes: class A { foo: string; constructor({ foo }: { foo: string }) { this.foo = foo; } equals(other: A) { return this.foo === other.foo; } } ...
leonheess's user avatar
  • 16.3k
3 votes
3 answers
109 views

PowerShell Classes: Is it possible to make a constructors parameter optional?

I am trying to build a "type", for the Timecode convention used in Film/Animation. I want to accommodate use cases where a user may want to initialise the object with a Timecode string ...
Ralf_Reddings's user avatar
0 votes
0 answers
30 views

Ignore constructor on deserialize from XML

I have a class with a List(of SomeKindOfObjects). In the constructor i applied a couple of instances to the list to preset the list for first use. The user can modify the list in the UI. E.g. The user ...
gegy's user avatar
  • 87
0 votes
1 answer
28 views

Function & object prototype [duplicate]

in this question Person has constructor function and pesron1 has instance or object that created by Person. hi guys, why this code return false Person.prototype === Object.getPrototypeOf(Person) and ...
Abolfazl Soltani's user avatar
0 votes
1 answer
30 views

How can I solve this Jiffy constructor error?

I am not sure the best constructor to add in this use case. Still trying to figure out flutter so I got stuck here while trying to build an app. I have tried the different constructors like "...
Imoleayo's user avatar
1 vote
1 answer
22 views

Julia - constructor error when a field is a Vector of Functions

I created a mutable struct with a field of type Vector{Function}. When I use a constructor with only this field as an argument, I get a MethodError. Here is minimalist example with a constructor with ...
Xavier Lebeuf's user avatar
0 votes
2 answers
56 views

Vector of class object

I was wondering how to create a vector of class object with custom constructors, though I ran into a problem with std::vector.push_back(), how am i supposed to create a new element in the vector with ...
nyedoardo's user avatar
0 votes
2 answers
63 views

Are private base class constructors still called?

#include <iostream> // first base class class Vehicle { public: Vehicle() { std::cout << "This is a Vehicle\n"; } }; // second base class class FourWheeler { public: ...
KAMLESH SINGH's user avatar
1 vote
1 answer
130 views

CodeIgniter 4: Too few arguments to function" error in controller constructor

I'm encountering an issue in my CodeIgniter project where I'm getting a "Too few arguments to function" error in the constructor of one of my controllers. I'm not sure why this error is ...
Rk Bishnoi's user avatar
0 votes
1 answer
32 views

Multiple constructors with different parameters in Python [duplicate]

I am getting an error in the following code. I used to write the same and it was working correctly. We can do multiple constructors with different parameters. When we run the program, the constructor ...
Salma bukhari's user avatar
0 votes
2 answers
53 views

Is this construct a proper use of a private class, and how do I put its instances in that map?

Trying to find a somewhat clean design for sampling billions of dice rolls and while my first ugly solution did work by just creating the generators for the known ranges (dice) it was an ugly mess of ...
Erik Itter's user avatar
2 votes
3 answers
114 views

Why can I initialize a class/struct with a scalar value?

I came across this behavior today and I can't find a reason for why it's working. Non-working code struct MyStruct { int x; int y; }; MyStruct foo = 1; error: conversion from ‘int’ to non-...
nullromo's user avatar
  • 2,175
4 votes
0 answers
103 views

C# What is doing this constructor if the attribute is not part of the class?

I had this line of code public SchedulerCust Scheduler; SchedulerCust is a custom class I wrote. Visual Studio gave me the option to refactor the before mentioned code to this: public Car(...
asd asd's user avatar
  • 98
2 votes
2 answers
108 views

What does is_constructible_v<std::string&&, std::string&&> mean by?

I can understand what is is_constructible_v<std::string, std::string&&>. But what does is_constructible_v<std::string&&, std::string&&> mean by? What is difference ...
myoldgrandpa's user avatar
2 votes
0 answers
80 views

Javascript Object() vs new Object() for ES6

I've seen a number of questions about new Object vs new Object() or new Object() vs {}, but I'm wondering about what the difference is between Object() and new Object()? In other words, what's the ...
mishar's user avatar
  • 369

1
2 3 4 5
419