Questions tagged [constructor]
A special type of subroutine called at the creation of an object.
151 questions
3votes
1answer
70views
Using std::variant for constructor
Need some input on using std::variant for the constructor. The top section explains why I have so man constructors. The review is really about the last bit of code ...
1vote
0answers
67views
Presence of UB and memory usage of a std::array initialization: version with temporary array on heap
I proposed several techniques to answer to https://stackoverflow.com/q/78672409/21691539. A classical way to answer would be to use std::index_sequence-based ...
3votes
1answer
240views
Presence of UB and memory usage of a std::array initialization
I proposed several techniques to answer to https://stackoverflow.com/q/78672409/21691539. A classical way to answer would be to use std::index_sequence-based ...
2votes
1answer
101views
in_place_constructor helper type
recently I implemented a little helper class, which can be primarily utilized on perfect forwarding constructors. Introduction As a slight example, let me pull in two of the ...
1vote
2answers
161views
A simple String class and its special member functions
I am learning the behavior of C++'s special member function, using a naive String class as example. (The code is modified from this tutorial) Here is the ...
6votes
2answers
1kviews
Classes representing 2D points and pixels
How can I improve this code or make it tidier? ...
1vote
1answer
72views
Tiny Validity class
Here is a part of my new code replacing the old and deprecated old-school one. Let's get to business right away: I document everything with Documentation comments, which are proving very useful so ...
6votes
3answers
239views
Performing complex operation before calling the primary constructor in Kotlin
Semester is a simple enum class. ...
0votes
1answer
144views
GameObject - Component hierarchy, component can access game object in constructor
While creating a game engine using c++, when defining a component, I was tired of writing down essential but repeated elements such as 'GameObject* parent' every time I define a new component ...
2votes
2answers
94views
Setting instance variable for salary bonus based on academic position
I have a class Scholar which is basically a teacher in a university. I have to calculate the yearly salary of a scholar instance where the formula is ...
0votes
1answer
69views
If constructor has actions besides assignment should I move those actions in separate method?
I have class CellGroup that contains List of cell lists That class has creation of list inside and transforming it to list of lists. ...
0votes
2answers
175views
Made a monster array for a text based game with a class constructor C++ [closed]
I created a class in a separate .h and .cpp file with the idea of having an array of 3 monsters with each monster having different stats( name; health; damage). The problem is that the constructor ...
4votes
1answer
254views
Commands Object creation using chained Builder pattern
Context As many of you may know I have a library that allows C++ objects to be converted into JSON/YAML/BSON automatically with a single declaration (see previous code reviews). I am now (trying) ...
10votes
2answers
728views
Clearing up property and field confusion in C#?
I understand that creating public properties that control private fields is good practice because of coupling and encapsulation, although lately I have seen it as such a waste of boilerplate code for ...
2votes
1answer
57views
Modify parameter data before creating an instance of a class in PHP
I have an abstract Badge class, every class extending this class should always correctly set the incoming name (string) and achievedAt (date) fields. There might be other classes that extend the Badge ...