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
7 answers

When do I have to use initializer lists for initializing C++ class members?

let's say I have std::map< std::string, std::string > m_someMap as a private member variable of class A Two questions: (and the only reason I'm asking is because I came across code like that) What's the purpose of this line: A::A() :…
Tom
  • 149
  • 3
  • 8
6
votes
8 answers

How to initialize a class?

The problem is really simple, I have a class "Stock", I want to load its property "StockName", "StockCode' from the db. so which patten should I use? pattern 1) Use service class to create it public interface IStockService{ Stock…
yi.
  • 61
  • 1
  • 2
6
votes
4 answers

1l for long, 1f for float, 1d for double, what about byte?

1l for long, 1f for float, 1d for double, what about byte? long l = 1l; float f = 1f; double d = 1d; // byte b = 1?; What's the equivalent for byte? Does it exist?
sp00m
  • 47,968
  • 31
  • 142
  • 252
6
votes
1 answer

uninitialized constant when using module in custom initializer

I'm working on a Rails (3.2) app and I need to execute some tasks when the app boots. Since I want to keep the logic in a separate file I have also create lib/helinium.rb that looks like (with dummy run method) class Helinium def self.run puts…
Sig
  • 5,476
  • 10
  • 49
  • 89
6
votes
2 answers

Default value for struct parameter

Let's say I have the following struct: struct myStruct { int x; int y; int z; int w; }; I want to initialize this struct to a default value when calling the following function. If it helps I'm looking for a simple zero initialization. void…
atoMerz
  • 7,534
  • 16
  • 61
  • 101
6
votes
1 answer

Simple program using uniform initialization to construct an object fails to compile

Consider the following program: struct X { X(int, int) { } X(X&&) { } }; int main() { X x( {0, 1} ); // Doesn't compile on ICC 13.0.1, compiles on // Clang 3.2, GCC 4.7.2, and GCC 4.8.0 beta. } When compiled with GCC…
Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
6
votes
4 answers

Python Instantiate Class Within Class Definition

I am attempting to add a variable to a class that holds instances to the class. The following is a shortened version of my code. class Classy : def __init__(self) : self.hi = "HI!" # "CLASSIES" variable holds instances of class…
Tanaki
  • 2,575
  • 6
  • 30
  • 41
6
votes
6 answers

initialize struct contain references to structs

Is it possible to have a struct containing references to structs. And how are these initialized? See short example below. Thanks typedef struct { int a; }typeInner1; typedef struct { int b; }typeInner2; typedef struct { typeInner1 &one; …
monkeyking
  • 6,670
  • 24
  • 61
  • 81
6
votes
4 answers

When are C++ implicit types initialized to 0?

I grew some doubts after discussing this with colleagues... As the title asks, when can it be assumed that built-in types will be initialized to 0 instead of an unknown value? Do the rules vary among the c++ standards?
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
6
votes
1 answer

Inherited const attribute and initialization (bug?)

I've been surprised that this code is actually considered correct (gcc 4.2.1) : class A { public: const int i; }; class B: public A { public: //B() {} }; so that I am able to let some attribute non initialized. The compiler complains when I try…
Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
6
votes
1 answer

Zero initialization of POD

struct Line { Bounds bounds_; Vector origin_; uint32_t begin_; uint32_t end_; dist ascent_; dist descent_; }; which is used as follows: Line line = {}; while…
Daniel Gehriger
  • 7,339
  • 2
  • 34
  • 55
6
votes
9 answers

Python __init__ setattr on arguments?

It seems that often __init__ methods are similar to this: def __init__(self, ivar1, ivar2, ivar3): self.ivar1 = ivar1 self.ivar2 = ivar2 self.ivar3 = ivar3 Is there someway to turn the arguments into a list (without resorting to *args…
mk12
  • 25,873
  • 32
  • 98
  • 137
6
votes
2 answers

Is it possible to create an instance of an class without running ANY code from the class? (no ctor, no field initializations)

I have created an engine that takes in 3rd party plugins (DLL's) that implement an interface. Since I have no control over the code that gets plugged in, I want to be able to run 1 specific method (from the interface) from the correct class…
Wolf5
  • 16,600
  • 12
  • 59
  • 58
6
votes
7 answers

How to initialize char array in struct

how to initialize a char array in structure in C# i am doing this struct cell { public char[] domain =new char[16]; public int[] Peers; public int NumberOfPeers; public char assignValue; } but its giving error that we cannot…
ssbb
  • 245
  • 2
  • 5
  • 12
6
votes
3 answers

What is the difference between declaring data attributes inside or outside __init__

Possible Duplicate: Python: Difference between class and instance attributes I'm trying to get my head around OOP in Python and I'm a bit confused when it comes to declare variables within a class. Should I declare them inside of the __init__…
1 2 3
99
100