Skip to main content

Questions tagged [constructor]

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

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 ...
Loki Astari's user avatar
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 ...
Oersted's user avatar
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 ...
Oersted's user avatar
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 ...
DNKpp's user avatar
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 ...
Der Fänger im Roggen's user avatar
6votes
2answers
1kviews

Classes representing 2D points and pixels

How can I improve this code or make it tidier? ...
user366312's user avatar
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 ...
Vlastimil Burián's user avatar
6votes
3answers
239views

Performing complex operation before calling the primary constructor in Kotlin

Semester is a simple enum class. ...
Hyeonseo Yang's user avatar
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 ...
김범무's user avatar
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 ...
tmo's user avatar
  • 33
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. ...
DozezQuest's user avatar
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 ...
Nis's user avatar
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) ...
Loki Astari's user avatar
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 ...
Josh Hallow's user avatar
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 ...
Miguel Stevens's user avatar

153050per page
close