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
1
vote
1 answer

Is it possible to limit the number of instances of a class at compile time?

Assume there is a class Foo that I, as the designer of a library, do not want my users to be able to instantiate more than n amount of times (where n is not necessarily 1). Is there any way to enforce this rule during compilation? Please note that I…
platisd
  • 153
  • 1
  • 9
1
vote
0 answers

varadic argument templated object creation on container not working

Below is a example (not the entire class, just relevant parts) class Container { private: size_t m_next_id; std::unordered_map m_objects; public: template size_t create(Args... args) { return…
1
vote
4 answers

Need a design pattern to remove enums and switch statement in object creation

Let's say I am creating a sports game, and in this game there are various positions a player can play, attack, defence, etc. So I start by creating a base class: public abstract class Position { public abstract string Name { get; } } and the…
DanDan
  • 10,462
  • 8
  • 53
  • 69
1
vote
2 answers

Deduced type from (const) *this used as template function template argument

I have simple class: #include template T make(const Ts&... args) //generic class maker { return T(args...); } template class A { public: A(void) : x_(T()), y_(T()) {} explicit A(int x)…
xinaiz
  • 7,744
  • 6
  • 34
  • 78
1
vote
0 answers

Constructing a valarray using raw data

It seems I might be using std::valarray<_Tp>s for some computational work (suppose _Tp is uint64_t). Unfortunately, the following hold: my code receives raw arrays - uint64_t*s and a length value - I can't change signatures/APIs. They're…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
2 answers

Forwarded in-place construction and list-initialization

By forwarded in-place construction, I take to mean std::allocator::construct and the various emplace methods, e.g., std::vector::emplace_back. I just find that forwarded in-place construction in C++ does not (unable to?) take advantage of the…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
1
vote
5 answers

in javascript creating object and manipulating properties

I create objects by two different ways and try to reach them and manipulate them. The object that I create by object constructor it work but same thing I try to do by literal notation doesn't work. I don't understand. here is code it will explain…
1
vote
1 answer

Inheritance in C++: Order of Construction

#include using namespace std; class Parent { public: Parent ( ) { cout << "P"; } }; class Child : public Parent { public: Child ( ) { cout << "C"; } }; int…
D Mehta
  • 433
  • 4
  • 11
1
vote
3 answers

Java: [Global method access] enum with a single instance vs on-demand object construction vs static

I want to create a class with few methods which can be used anywhere inside a package. I opted to use enum with a single instance after reading that it automatically provides safe instantiation, serialization and protection from instantiating…
yalkris
  • 2,596
  • 5
  • 31
  • 51
1
vote
4 answers

Should I load my Java object's data on construction, or explicitly through a method call?

This is a design question. I'm trying to decide between 2 implementations. In order to properly explain this I need an example. So, for the sake of example: I have a class that generates a report about, let's say, certain Stock Market values on a…
froadie
  • 79,995
  • 75
  • 166
  • 235
1
vote
3 answers

Does assignmentless Construction of an Object Make any Sense?

A R# inspection of my solution told me "'Local variable 'fs' is never used'" about this line: var fs = new FormatString(); Okay, then; just get rid of the whole shebang, right? Instead, R#'s action was to remove just the var declaration and…
1
vote
1 answer

Java nullPointerException in filling object Hierarchy with saxParser

I am filling an array of rooms with room objects and creatures into their respective rooms from an xml file using saxParser. I having trouble figuring out why I seem to be losing everything in the array once I leave my conditional statements in my…
1
vote
1 answer

Javascript strange behavior in function (constructor) return types

Assume we have two functions like the followings : function a(){ this.x = 5; return {z:20};} function b(){ this.x = 5; return 30;} now if you run these lines everything seems to be reasonable: a(); //output : {z:20} b(); //output : 30; but if…
Mahmoud Moravej
  • 8,705
  • 6
  • 46
  • 65
1
vote
1 answer

Really weird object creation JS benchmark

I've made a simple object creation benchmark. I know "there are lies, damn lies and benchmarks", however the difference seems huge. Can anyone tell me if I'm doing something wrong. Or if not, how is it possible? I'm new to JS so please don't beat…
1
vote
1 answer

EclipseLink Profiler shows multiple registered object being created

In my development environment when i run a ReadAllQuery using a simple get all JQPL query, i noticed after using the EL profiler that there several read object queries that get executed each adding time to my total time. For example, running a query…
Warz
  • 7,386
  • 14
  • 68
  • 120