Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [object-construction]

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

object-construction
3 votes
1 answer
81 views

explicit deleted constructors - does this matter?

When marking a constructor as deleted, i.e. class MyClass { // ... MyClass(int x) = delete; // ... }; is there any effect to marking the deleted constructor as explicit? i.e. ...
einpoklum's user avatar
  • 127k
13 votes
3 answers
1k views

Is it legal to initialize an array via a functor which takes the array itself as a parameter by reference?

In the question Idiom for initializing an std::array using a generator function taking the index?,which basically asks how one can initialize an array of an arbitrary type which is not necessarily ...
Weijun Zhou's user avatar
  • 4,081
3 votes
0 answers
69 views

How come I can capture an object being constructed in the lambda doing the construction? [duplicate]

Consider the following code: int x = [&x](){ std::cout << "Inside lambda, x is " << x << '\n'; x = 5; return 23; }(); std::cout << "x is " &...
einpoklum's user avatar
  • 127k
6 votes
2 answers
444 views

Idiom for initializing an std::array using a generator function taking the index?

Suppose I have a function T foo(size_t i). What would be an elegant and succinct way of constructing an object arr, of type std::array<T, N>, so that we have arr[i] == foo(i)? If possible, I ...
einpoklum's user avatar
  • 127k
0 votes
1 answer
111 views

Snowflake query to create json - multiple results for single attribute

I have a table in snowflake that has three different columns being used as name type/values. These need to be mapped in an MDM tool using json. Of course, I cannot use the same attribute name more ...
Scott J's user avatar
0 votes
1 answer
83 views

Constructing lambdas in constructors

I had some nasty bugs when constructing lambdas in constructors when working with callback-based event system. Here's simple scenario: class Object { public: int variable = 10; std::function&...
Rostys's user avatar
  • 79
0 votes
0 answers
33 views

Trouble constructing a map with immovable value types from initializer list [duplicate]

Consider the following code: #include <map> #include <type_traits> #include <memory> void foo() { using map_type = std::map<int, std::unique_ptr<float[]>>; auto ...
einpoklum's user avatar
  • 127k
1 vote
2 answers
179 views

Using a method to create objects

I have a question regarding creating object using a method, please see my code below: import java.util.ArrayList; import java.util.Scanner; public class Student { private String name; private ...
Jack M's user avatar
  • 61
0 votes
0 answers
38 views

Calling multiple async operations in a C# class initializer

Given a C# class like this public class MyData { public int Value1 { get; set; } public int Value2 { get; set; } } Could it ever create a concurrency problem to instantiate and initialize ...
R26's user avatar
  • 11
0 votes
1 answer
56 views

Mocking object construction in unit tests

I would like to write unit tests for a class which creates an instance of a problematic class, and I am working under the following constraints: My class calls some third-party library initialization ...
Danilo Piazzalunga's user avatar
5 votes
1 answer
479 views

Why does object.__new__ accept parameters?

Besides the obvious asking "again" about __new__ and __init__ in Python - I can ensure, I know what it does. I'll demonstrate some strange and to my opinion undocumented behavior, for which ...
Paebbels's user avatar
  • 16k
0 votes
1 answer
246 views

Python Factory Method Suggestions

I would like to ask you to help me out with my factory method. I have to handle multiple and periodic csv objects, each of which has its own properties, thus its own class. The only way I can tell ...
Marco's user avatar
  • 47
1 vote
1 answer
41 views

How can I create new objects with user defined properties every time a function is called in JavaScript?

Apologies if this is a stupid question, I'm very much a beginner here. I run a D&D game, and I thought a good thing to practice coding with would be a simple initiative tracker. At the moment, I'm ...
Holly Wilson's user avatar
1 vote
1 answer
405 views

Why does std::map crash when it is declared static inline inside a class and used early?

I have found several times that when a std::map is declared inside a class as a static inline (C++ 17), struct MyStruct { static inline std::map <A, B> mymap; MyStruct(A& a, B& ...
Peter Fletcher's user avatar
0 votes
3 answers
70 views

object Object being written [duplicate]

I am very new to JS and am playing around trying to output this verify function I came across below. In my limited thinking I thought that the result would be false and I would be able to write that ...
Mike Devine's user avatar

15 30 50 per page
1
2 3 4 5
7