Questions tagged [object-construction]
For questions related to object construction, usually in an OOP environment.
object-construction
105
questions
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.
...
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 ...
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 " &...
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 ...
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 ...
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&...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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& ...
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 ...