Questions tagged [construction]

Use for questions related to building a data structure, such as a heap.

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.

110 questions
622
votes
16 answers

How can building a heap be O(n) time complexity?

Can someone help explain how can building a heap be O(n) complexity? Inserting an item into a heap is O(log n), and the insert is repeated n/2 times (the remainder are leaves, and can't violate the heap property). So, this means the complexity…
GBa
  • 14,931
  • 15
  • 47
  • 67
38
votes
9 answers

Thread safe lazy construction of a singleton in C++

Is there a way to implement a singleton object in C++ that is: Lazily constructed in a thread safe manner (two threads might simultaneously be the first user of the singleton - it should still only be constructed once). Doesn't rely on static…
pauldoo
  • 16,381
  • 20
  • 85
  • 112
15
votes
3 answers

What is an int() Called?

It's been rehashed over and over that primitive types don't have constructors. For example this _bar is not initialized to 0 when I call Foo(): class Foo{ int _bar; }; So obviously int() is not a constructor. But what is it's name? In this…
Jonathan Mee
  • 35,107
  • 16
  • 95
  • 241
11
votes
9 answers

Programmatic HTMLDocument generation using Java

Does anyone know how to generate an HTMLDocument object programmatically in Java without resorting to generating a String externally and then using HTMLEditorKit#read to parse it? Two reasons I ask: Firstly my HTML generation routine needs to be…
Tom Klapiscak
  • 111
  • 1
  • 1
  • 3
11
votes
2 answers

Referencing the same variable that you're declaring

I've seen the following type mistake a couple of times while working with C++ code: QString str = str.toUpper(); This can be a fairly easy mistake to make and yet it compiles and executes (sometimes with crashes, sometimes without). I can't see any…
Chris
  • 15,555
  • 3
  • 49
  • 58
10
votes
2 answers

Shouldn't the temporary A(3) be destroyed before "Here" is printed?

Shouldn't the temporary A(3) be destroyed before "Here" gets printed? #include struct A { int a; A() { std::cout << "A()" << std::endl; } A(int a) : a(a) { std::cout << "A(" << a << ")" << std::endl; } ~A() { std::cout <<…
9
votes
3 answers

jquery widget, _create or _init

Some jquery plugin extend widget use _create method, while others use _init method, can someone explain the differences between the two? Also any guidance on when it is better to extend widget or directly extend jquery.fn?
Gelin Luo
  • 13,399
  • 23
  • 77
  • 119
8
votes
2 answers

Does anyone know why the TWEAK routine gets hit before the BUILD routine?

Minimal code: #!/usr/bin/raku class Widget { submethod TWEAK(:$content, :$styles) { say "t1\n"; } } class File is Widget { submethod BUILD() { say "b1"; } } my $xml =…
Timothy Nelson
  • 313
  • 2
  • 4
8
votes
3 answers

Building a Binary Tree (not BST) in Haskell Breadth-First

I recently started using Haskell and it will probably be for a short while. Just being asked to use it to better understand functional programming for a class I am taking at Uni. Now I have a slight problem I am currently facing with what I am…
8
votes
5 answers

Is Object constructor called when creating an array in Java?

In Java, an array IS AN Object. My question is... is an Object constructor called when new arrays is being created? We would like to use this fact to instrument Object constructor with some extra bytecode which checks length of array being…
Peter Štibraný
  • 31,128
  • 15
  • 85
  • 114
8
votes
2 answers

Construction of temporary in function call is interpreted as declaration

Lately I ran into a problem which somehow (but only somehow) makes sense to me. It is based on interpreting the construction of a temporary as declaration of the single (!) constructor argument. Please have a look at the minimal example…
sedriel
  • 83
  • 4
7
votes
5 answers

Abstract syntax tree construction and traversal

I am unclear on the structure of abstract syntax trees. To go "down (forward)" in the source of the program that the AST represents, do you go right on the very top node, or do you go down? For instance, would the example program a = 1 b = 2 c = 3 d…
Seth Carnegie
  • 70,115
  • 19
  • 169
  • 239
6
votes
4 answers

Other way to prohibit a certain C++ class construction except than declaring the constructor private?

Say I have a class with some const reference member variable and I would like to forbid a certain type of construction. So I would declare the according constructor private. Of course, a constructor must initialise all const reference member…
ritter
  • 6,405
  • 7
  • 43
  • 79
6
votes
1 answer

How to in-place-construct an optional aggregate?

How to in-place construct an optional aggregate? It seems I can only construct an optional single thing, and not an optional aggregate of things. #include #include struct Unmovable { Unmovable(const Unmovable&) = delete; …
user2394284
  • 4,224
  • 3
  • 24
  • 28
6
votes
4 answers

Understanding the efficiency of an std::string

I'm trying to learn a little bit more about c++ strings. consider const char* cstring = "hello"; std::string string(cstring); and std::string string("hello"); Am I correct in assuming that both store "hello" in the .data section of an application…
flumpb
  • 1,561
  • 1
  • 14
  • 31
1
2 3 4 5 6 7 8