Questions tagged [object-construction]

For questions related to object construction, usually in an OOP environment.

Construction is a concept of Object-Oriented languages.

Objects need to be setup for use:

  • Their member variables need to be allocated
  • Any Object member variables also need to be constructed
  • The Object methods need to be setup for calling

This process is accomplished by construction.

95 questions
0
votes
1 answer

How do I name an Object inside of an Object Constructor someone's Discord Username?

I am trying to create an object constructor in a JSON file for Discord. The large constructor is named "person" and I want the objects inside of that to be the Discord Message Author's name, but I can't name the variable "msg.author.username". What…
0
votes
3 answers

Why does creating objects with constructor execute object's method in javascript?

Suppose I want to have three objects of type Room. The three objects would be bedroom, livingroom and bathroom. Room has two properties length and breadth, and one method myFunc. I use constructor method to create the three required objects…
user31782
  • 7,087
  • 14
  • 68
  • 143
0
votes
1 answer

Is generic list construction ignored if the instance already exists?

I've got this code: if (null == _priceComplianceSummaryList) { _priceComplianceSummaryList = new List(); } Resharper flags it as an issue, suggesting, "Replace 'if' statement with respective branch" If I acquiesce, the…
0
votes
1 answer

How do you construct an object without initializing it? (.net)

When you new an object in C# a few things must happen: memory for the object is created, and whatever other book-keeping CLR whats to do fields are initialized to default values the constructor is invoked Serialization frameworks seem to have some…
Tim Lovell-Smith
  • 15,310
  • 14
  • 76
  • 93
0
votes
4 answers

Swift: Protocol Based Type Construction

I'm trying to create a protocol in Swift I can use for object construction. The problem I'm running into is that I need to store the type information so the type can be constructed later and returned in a callback. I can't seem to find a way to…
Aaron Hayman
  • 8,492
  • 2
  • 36
  • 63
0
votes
3 answers

Extending prototype on object literal

If I have the following code, why does it return an error saying Cannot set property 'second_prop' of undefined . I thought that you can extend the prototype property and add more variables and methods to the object prototype. Since the two console…
user1142130
  • 1,617
  • 3
  • 20
  • 34
0
votes
1 answer

How to convert a @ToString generated string back to object with Groovy

For example, instance of the following following class produces string A(x:7, values:[hello, world]) @ToString( includeNames=true ) class A { def x def values = [] } How can I transform this String back to an instance of the class?
kaskelotti
  • 4,709
  • 9
  • 45
  • 72
0
votes
1 answer

Undertanding starting object construction process and UB

The following example is given in the 12.7/3 N3797 struct A { }; struct B : virtual A { }; struct C : B { }; struct D : virtual A { D(A*); }; struct X { X(A*); }; struct E : C, D, X { E() : D(this), // undefined: upcast from E* to A* …
user2953119
0
votes
1 answer

How to reconstruct R objects without writing them in a file?

I have R object which is to be shared with another analyst. I write: dput(objectname,"filename.R") and then the object can be reconstructed by sharing the .R file and using the dget(filename.R) function. Now what I want to do is just share the…
Aman Mathur
  • 709
  • 2
  • 15
  • 27
0
votes
4 answers

Why can't I create a vector using a pointer and length

Suppose I want to construct a C++ STL vector from an array (knowing its length), i.e. I have: size_t length = /* ... */ int *a = new int[length]; I can construct the vector this way: std::vector v(a, a + length); but not this…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
1 answer

Add value to list item depending on another list item value

I am using this code to populate a list in C# with data from a Web Api that gets data from a csv file HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync("http://localhost:12345/api/items"); var info = new…
Tester
  • 2,887
  • 10
  • 30
  • 60
0
votes
1 answer

How to use dynamic key name in object during object construction?

I want to use a dynamic key name during the creation of the object. var myKey = 'text'; var myObj = { [myKey]: 'Hello' // not working }; alert(myObj.text); I know you can do it on the next line after the object is created myObj[key] =…
0
votes
2 answers

Creating an object without a default constructor

I have a package which has some N number of classes and I'm scanning all the classes and initializing them through a method. All the classes with a default constructor are being initialized but the ones without default(zero argument) constructor…
iuser
  • 209
  • 1
  • 6
  • 18
0
votes
1 answer

If Hungarian notation is mostly disparaged why is "UpperCamel for constructors vs lowerCamel for everything else" so popular?

It seems to be the case at least here on StackOverflow that Hungarian notation is most often considered to be a bad thing (though a minority are still in favour). Now in the JavaScript world where I've been doing most of my coding for the past few…
-1
votes
2 answers

Delete object's variable after instantiation

So I have an object which needs certain variables to be instantiated. These variables are passed to the object through an array of objects. Then, each element in the array gets assigned to an internal variable. Does this array get garbage collected…
spcan
  • 138
  • 5