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

Concise way to enforce implementation of factory in Scala

Let us assume we have a trait T. What is the best way to achieve the following: Everybody who writes an implementation of T should be forced to provide a possibility that allows a parameter-free initialization of T, i.e., we probably have to…
bluenote10
  • 23,414
  • 14
  • 122
  • 178
6
votes
7 answers

Array Type - Rules for assignment/use as function parameter

when I need to pass an array to a function, it seems all the following declarations of the function will work void f(int arr[]) void f(int arr[4]) // is this one correct? for this: int a[]={1,2,3,4}; f(a); But when I assign an array to another…
Tim
  • 1
  • 141
  • 372
  • 590
6
votes
2 answers

spring mvc servlet initialization

I am new to spring MVC. I am looking for a place in my spring mvc applicationwhere I can initialize all sorts of things in the application. usually I did that in the init() method of the my main servlet but now the dispatcher servlet is of spring…
rperez
  • 8,430
  • 11
  • 36
  • 44
6
votes
1 answer

Initialize a constexpr array as sum of other two constexpr arrays

Given two constexpr arrays (type[N] or std::array) constexpr int A[5] { 0, 1, 2, 3, 4 }; constexpr int B[5] { 5, 4, 3, 2, 1 }; is it possible to initialize a new constexpr array performing an element-wise operation (or constexpr…
AkiRoss
  • 11,745
  • 6
  • 59
  • 86
6
votes
2 answers

Linux shared library init & deinit when also using c++ static initializer

I want to have automated calls to initialize and deinitialize my shared library. In my shared library, I need some static initialization of C++ objects, among others because of use of third party code (e.g. UnitTest++). When my init function is…
Joe
  • 3,090
  • 6
  • 37
  • 55
6
votes
2 answers

How do I set multiple int's equal to the same number ? Java

I have the code int index, r, g, b; and I want to set all of them equal to a certain number, I don't individually want to write index = 0; r = 0;... and so on. How do I do this in java? index,r,g,b = 0; doesn't work for me.
user2893243
  • 319
  • 2
  • 3
  • 10
6
votes
3 answers

Best practice for saving data in abstract classes

So, just as an example, let's say we have an abstract class called Question, that question contains a lot of strings, one for the question itself, one for the answer and two responses posted to the user, if he got the question right / wrong. public…
felix fritz
  • 462
  • 2
  • 5
  • 21
6
votes
2 answers

How to initialize const circular reference members

For example, I have two classes class Foo; class Bar; class Foo { const Bar &m_bar; ... }; class Bar { const Foo &m_foo; ... }; Let foo is object of Foo and bar is object of Bar. Is there any way (normal or "hacking") to create/initialize…
6
votes
1 answer

iOS app failed to launch in time 0x000000008badf00d - delay in applicationDidBecomeActive

I put entire didFinishLaunchingWithOptions with minimal code which is here: [UIApplication sharedApplication].idleTimerDisabled = YES; m_bDataLoadingNeeded = YES; return YES; As a result, I had to put crucial initialization in…
Nirav Bhatt
  • 6,940
  • 5
  • 45
  • 89
6
votes
2 answers

How can I initialize a generic variable in Java?

I am trying to write a method in which I need to create a temp variable, sum, of generic type T. However, I'm getting the error "The local variable sum may not have been initialized". How can I initialize a generic variable? I can't set it to 0 or…
woollyMammoth
  • 105
  • 1
  • 2
  • 7
6
votes
3 answers

The local variables are not static but why do I get this behaviour?

When I teach C, sometimes I count on GCC to do the "convincing" part of some rules. For example, one should not consider that a local variable on a function retains the value between calls. GCC always helped me to teach these lessons to students,…
DrBeco
  • 11,237
  • 9
  • 59
  • 76
6
votes
5 answers

VBA: Userform initialize method not being hit when userform initializes

My module code calling the userform: PreInfo.Show My userform code: Public Sub PreInfo_Initialize() Dim Invoice, Name, Model, Crank, MyValue1, StrokeL As Variant 'Dim ListBox1 As ListBox Dim c As Range Dim oneControl As Object 'Empty Text Boxes…
Alex Barrie
  • 93
  • 1
  • 1
  • 6
6
votes
2 answers

Initialize in Ruby

I used to have this public constructor_name() { this(param) } public constructor_name(int param) { this.param = param } in Java and what about ruby do we have this kind of self reference constructor ?
sarunw
  • 8,036
  • 11
  • 48
  • 84
6
votes
2 answers

Initialize a Struct containing a const array with initializer list

I working with C++11 and have a Class containing the following Struct: struct Settings{ const std::string name; const std::string* A; const size_t a; }; class X { static const Settings s; //More stuff }; In the .cpp file I…
Haatschii
  • 9,021
  • 10
  • 58
  • 95
6
votes
3 answers

Handling uninitialized Strings in Java

Here's part of a small program I'm doing as a homework assignment: public Exam maxGrade() { Node p = firstNode; int max = 0; String name; while (p!=null) { if (p.info.getGrade()>max) { max = p.info.getGrade(); …
user2397616
  • 93
  • 1
  • 1
  • 6
1 2 3
99
100