initialization

NSObject default constructor

Hi all, The default constructor of NSObject is this? -(id)init { return self; } thanks! ...

Partially initialize variable defined in other module.

I'm considering a certain solution where I would like to initialize a cell of an array that is defined in other module (there will be many modules initializing one table). The array won't be read before running main (so there is not problem with static initialization order). My approach: /* secondary module */ extern int i[10]; // th...

__init__ method for form with additional arguments

I'm calling my form, with additional parameter 'validate : form = MyForm(request.POST, request.FILES, validate=True) How should I write form's init method to have access to this parameter inside body of my form (for example in _clean method) ? This is what I came up with : def __init__(self, *args, **kwargs): try: validate...

Datatables reInitialization (jQuery)

When I load my page in first place there nothing in the table and the datatable is not initializated, after a few interactions rows are added and when all rows are added (with ajax calls) I init the datatable this way: oTable = $('#table).dataTable( { "bJQueryUI": true, "bSortClasses": false, "sDom":'...

initializing char arrays in a way similar to initializing string literals

Suppose I've following initialization of a char array: char charArray[]={'h','e','l','l','o',' ','w','o','r','l','d'}; and I also have following initialization of a string literal: char stringLiteral[]="hello world"; The only difference between contents of first array and second string is that second string's got a null charact...

Static const initialization iPhone/Release

I have a cross platform library that has strange problem only on iPhone and only under release. // .h class cColor { public: static const cColor Red; static const cColor Green; static const cColor Blue; u8 r; u8 g; u8 b; u8 a; inline cColor(...) : ... { } }; // .cpp const cColor cColor::Red(0xFF, 0x00, 0x00);...

Exception throwable constructors & initialization. Best practice

I have DataProvider class (DAL) that requires "year" as parameter. It used like this: using (var provider = new DataProvider(year)) { provider.SomeRepostitory.DoSomethingUsefull(); } DataProvider constructor code deals with configuration - so it can throw exceptions. And exception throwable constructors are not recommended. So I a...

How can I make sure an object has finished initialising before using it?

Writing some Objective-C in one method, I call +alloc, then -init to set up an object. object = [[MyClass alloc] init]; [object useFor:whatever]; The next few lines of code use the newly created object. If the aforementioned -init takes too long, I’m sure the program won’t “wait” before starting to use the new object, will it? If not...

difference between initializing on declaration and on object construction

Possible Duplicate: Best Practice: Initialize class fields in constructor or at declaration? Is there any difference between these two classes? public class Test { public Guid objectId = Guid.NewGuid(); } public class Test2 { public Guid objectId; public Test2() { objectId = Guid.NewGuid(); } } ...

Is there a better way to initialize an allocated array in C++?

How to write this in another (perhaps shorter) way? Is there a better way to initialize an allocated array in C++? int main(void) { int* a; a = new int[10]; for (int i=0; i < 10; ++i) a[i] = 0; } ...

a way to omit taking names for objects that are used only to construct a final object

Suppose we have following two classes: class Temp{ public: char a; char b; }; class Final{ private: int a; char b; char c; public: Final(Temp in):b(in.a),c(in.b){} //rest of implementation }; suppose the only use of objects of Temp class is to construct objects of Final class, so I wonder if in current standard of c++...

perl array initialization

Hi, How do I initialize an array to 0. I have tried this. my @arr = (); but it always throws me a warning "Use of uninitialized value" I do not know the size of the array before. I fill it dynamically. I thought the above piece of code was supposed to initialize it to 0. Can anybody tell me how to do this. Thank you. ...

Complex initialization of const fields

Consider a class like this one: class MyReferenceClass { public: MyReferenceClass(); const double ImportantConstant1; const double ImportantConstant2; const double ImportantConstant3; private: void ComputeImportantConstants(double *out_const1, double *out_const2, double *out_const3); } There is a routine (ComputeIm...

will be this initialization syntax valid in upcoming c++0x standard ?

Suppose we have following two classes: class Temp{ public: char a; char b; }; class Final{ private: int a; char b; char c; public: Final(Temp in):b(in.a),c(in.b){} //rest of implementation }; can we initialize an object of the Final class with following syntax in upcoming c++0x standard: Final obj(Temp{'a','b'}); ...

How can class fields be initialized?

A bit of a basic question, but I'm having difficulty tracking down a definitive answer. Are initializer lists the only way to initialize class fields in C++, apart from assignment in methods? In case I'm using the wrong terminology, here's what I mean: class Test { public: Test(): MyField(47) { } // acceptable int MyField; };...

Initializer list makes variable uninitialized?

I have a class with the only constructor like this: IntroScreen::IntroScreen(Game *game) : View(game), counter(0.0f), message(-1), continueAlpha(255), continueVisible(false), screenAlpha(255), fadeIn(false), fadeOut(false) { } And somewhere in a method I have this if-statement if (counter > 10.0f) And Valgrind says for that...

When is memory allotted to static variables in C++

Hi ! I am a newbie to C++ and facing a problem. I read in a book that memory is allotted to a static variable, once the object is created of that class. Now, what if I make this static variable global ? When would be it initialized in that case ? Plus, I have also read in some articles that static variables are allotted on heap and the...

which kinds of constructors may be applied during compile time as optimization, for objects with static storage duration?

take two following classes and their constructors as samples: class One{ public: One(int a,int b):adad1(a),adad2(b){} private: int adad1; int adad2; }; class Two{ public: Two(int input[]){ for (int i=0;i<10;i++) araye[i]=input[i]; } private: int araye[10]; }; considering objects with static storage duration, I t...

does adding a dummy parameter to constructors of a class to solve calling ambiguity, violate any rule ?

take following class and two object definitions: class Rect{ public: enum centimeter; enum meter; Rect(double len,double wid,enum centimeter){ length=(len/100); width=(wid/100); } Rect(int len,int wid,enum meter){ length=len; width=wid; } //rest of implementation private: double length;//in meters double ...

relation between access specifiers and using initializer lists for POD types in c++0x.

take two following classes: class Test1{ public: Test1()=default; Test1(char in1,char in2):char1(in1),char2(in2){} char char1; char char2; }; class Test2{ public: Test2()=default; Test2(char in1,char in2):char1(in1),char2(in2){} private: char char1; char char2; }; I know in c++0x both of these classes are considered...