Questions tagged [initialization]

Initialization deals with the task of initializing the contents of your data structure. It's a common practice in statically-typed languages.

Initialization deals with the task of initializing the contents of data structures. This is the initialization of an object, structure, blob of data, or any entity which contains state that must be prepared prior to usage of the entity.

11649 questions
6
votes
2 answers

Using (or not using) parentheses when initializing an array

In the c++ code that I am reading through there are some arrays initialised like int *foo = new int[length]; and some like int *foo = new int[length](); My quick experimentation could not detect any difference between these two, yet they are used…
Jekowl
  • 317
  • 2
  • 12
6
votes
1 answer

Why are instance initialization blocks executed before constructors

I know that static blocks are initialized at the time the class is loaded and since the class is loaded only once in a program,they are initialized only once. IIB (Instance initialization blocks) are initialized every time an instance of the class…
Frosted Cupcake
  • 1,909
  • 2
  • 20
  • 42
6
votes
2 answers

Why is the size of a heap-allocated array required with initializer-list initialization?

While I can write int n[] {1, 2, 3}; I cannot write int *m = new int[] {1, 2, 3}; which should be int *m = new int[3] {1, 2, 3}; What is the reason for this?
user3810155
6
votes
4 answers

How to resolve designated initialization error for UITableViewController?

I'm new to swift and I'm having problems declaring my initializer in my PlacesTableViewController class. It prompts me "Super.init isn't called before returning from initializer" and when I added the Super.init, it prompts me: "Must call a…
6
votes
1 answer

PySide.QtGui RuntimeError: '__init__' method of object's base class not called ...but it was

Some environment basics Python Version: 3.4.2 OS: Windows 8.1 Searching so far, I suspect this other question is related to my issue at hand, but I'm not sure how I'm replicating enough of the same conditions--probably my lack of in-depth python…
LastTigerEyes
  • 647
  • 1
  • 9
  • 21
6
votes
2 answers

Struct Initialization Error

I know how to initialize structs (generally), but I'm having troubles with this struct within a struct stuff typedef struct Location{ uint8_t x; uint8_t y; } loc; typedef struct Person{ loc location; } person; global variables: static…
Justin
  • 61
  • 2
6
votes
1 answer

std::map default value for enums

Let's say we have: enum X { X1, X2, X3 }; int func() { std::map abc; ... } Assume 0 is the key that is not in the container. I know abc[0] needs to value-initialize the X object. Here are the questions: (1) Will the…
user3277360
  • 127
  • 4
6
votes
5 answers

How is a constructor executed?

I am making some revisions from the lecture slides and it says a constructor is executed in the following way: If the constructor starts with this, recursively execute the indicated constructor, then go to step 4. Invoke the explicitly or…
simion
  • 553
  • 3
  • 9
6
votes
1 answer

Uniform and Value-initialization

I try to use value-initialization for members with value-initialization for constructors (I don't know if I really use the good terms...) So... When I define: struct A { int a_; }; I'm able to use: A a{5}; assert(m.a_==5); However, if I want…
fp12
  • 63
  • 4
6
votes
3 answers

Static variable inside a constructor, are there any drawbacks or side effects?

What I want to do: run some prerequisite code whenever instance of the class is going to be used inside a program. This code will check for requiremts etc. and should be run only once. I found that this can be achieved using another object as static…
mip
  • 8,355
  • 6
  • 53
  • 72
6
votes
5 answers

Phase 1 and Phase 2 initialization in Swift

This is copy from Apple Swift documentation: As soon as all properties of the superclass have an initial value, its memory is considered fully initialized, and Phase 1 is complete. The superclass’s designated initializer now has an opportunity…
potato
  • 4,479
  • 7
  • 42
  • 99
6
votes
1 answer

Initialization and lambda-type argument

I have such a utility class: struct Atreturn { std::function funcdestr; Atreturn( std::function fd ): funcdestr(fd) {} ~Atreturn() { funcdestr(); } }; Note no explicit attribute at constructor. Possible use should…
Ethouris
  • 1,791
  • 13
  • 18
6
votes
2 answers

What's wrong with this initialization of unique_ptr?

Can somebody tell me, what is wrong with the following initialization of unique_ptr? int main() { unique_ptr py(nullptr); py = new int; .... } g++ -O2 xxx.cc -lm -o xxx -std=c++11 says: error: no match for ‘operator=’ (operand types are …
Gerdos
  • 63
  • 1
  • 3
6
votes
2 answers

How to autowire properties bean from Condition

Does have anyone way to autowire bean in Condition? There is an next example. We have 2 implementation of FileManager. One of implementation should be initialize in depends on property 'platform'. Properties handles via Archaius. @Component public…
6
votes
3 answers

Is this pointer initialization necessary?

Lets say I have the following: CHARLINK * _init_link(CHARLINK **link) { short i; (*link)->cl = (CHARLINK **) calloc(NUM_CHARS, sizeof(CHARLINK *)); for (i = 0; i < NUM_CHARS; i++) (*link)->cl[i] = NULL; return…
user318747
  • 1,418
  • 2
  • 16
  • 29