initialization

Is there a special object initializer construct in PHP like there is now in C#?

I know that in C# you can nowadays do: MyObject a = new MyObject() { Property1 = 1, Property2 = 2 }; Is there something like that in PHP too? Or should I just do it through a constructor or through multiple statements; $a = new MyObject(1, 2); $a = new MyObject(); $a->property1 = 1; $a->property2 = 2; If it is possible but...

Any reason to prefer memset/ZeroMemory to value initialization for WinAPI structs?

In Win32 programming a handful of POD structs is used. Those structs often need to be zeroed out before usage. This can be done by calling memset()/ZeroMemory() STRUCT theStruct; ZeroMemory( &theStruct, sizeof( theStruct ) ); or by value initialization: STRUCT theStruct = {}; Although the two variants above are not equivalent in g...

How does AppDomain initialise in a navite application which hosts .NET components.

Hi Folks, We have some .NET classes exposed as COM components. A customer has a service which utilises these COM components from a multithreaded C++ application. Things generally work fine but in some cases we are seeing issues queuing requests onto the System.Threading.Threadpool in this environment. Basically when we go to queue a user...

Initialization of const variables

Hi all, I have code like this: bool doSomething() { std::cout << "I'm here!" return true; } const bool x = doSomething(); If placed in a cpp-file in my Visual C++ console application, the code is executed as expected before entering the main() method. However, if I place this code in a .cpp-file inside a static link library pro...

num_get facet and stringstream conversion to boolean - fails with initialised boolean?

I have inherited a template to convert a string to a numerical value, and want to apply it to convert to boolean. I am not very experienced with the stringstream and locale classes. I do seem to be getting some odd behaviour, and I am wondering if someone could please explain it to me? template<typename T> T convertFromString( const ...

Allow for loop initialization in GCC and Clang when std={c,gnu}89?

How can I enable for loop initialization when compiling in c89 or gnu89 mode using GCC and Clang? ...

How to adapt my current splash screen to allow other pieces of my code to run in the background?

Currently I have a splash screen in place. However, it does not work as a real splash screen - as it halts the execution of the rest of the code (instead of allowing them to run in the background). This is the current (reduced) arquitecture of my program, with the important bits displayed in full. How can I adapt the splash screen curr...

Is there any problem of calling functions in the initialization list?

Hi, I'm writing this copy constructor: //CCtor of RegMatrix RegMatrix::RegMatrix(const RegMatrix &other){ this-> numRow = other.getRow(); this-> numCol = other.getCol(); //Create _matrix = createMatrix(other.numRow,other.numCol); int i,j; //Copy Matrix for(i=0;i<numRow; ++i){ f...

Two different Output...

#include<stdio.h> int main(void) { static int i=i++, j=j++, k=k++; printf("i = %d j = %d k = %d", i, j, k); return 0; } Output in Turbo C 4.5 : i = 0 j = 0 k = 0 In gcc I'm getting the error: Initializer element is not constant Which one is logically correct ? I'm in bit confusion.. ...

Error defining and initializing multidimensional array

I get error in compilation with the following definition. int matrix[ ][ ] = { { 1, 2, 3}, {4,5,6} }; char str[ ][ ] = { "abc", "fgh" }; Why is the compiler complaining missing subscript and too many initializers. ...

Objective-C initialize (static method) called more that once?

I have code similar to this in Objective-C: SubclassOfNSObject *GlobalVariableThatShouldNeverChange; @implementation MyClass +(void) initialize { [super initialize]; GlobalVariableThatShouldNeverChange = [[SubclassOfNSObject alloc] init]; // Change more stuff with GlobalVariableThatShouldNeverChange } @end I have this r...

Objective-C Proper way to create class with only one instance

I am trying to implement a class, that subclasses NSObject directly, that can only have one instance available throughout the entire time the application using it is running. Currently I have this approach: // MyClass.h @interface MyClass : NSObject +(MyClass *) instance; @end And the implementation: // MyClass.m // static inst...

will initialize break the layout settings in rails?

In one of the controller, I need a specific layout. I added layout at the beginning. It works well. But if I add an initialize function for some controller-based variable. Rails seems just ignore the layout command. Is anyone have same problem? How can I fix it? class AdminsController < ApplicationController layout "layout_admins"...

I have lots of questions about c++ that are really confusing me

I started learning c++ about 3 weeks ago after 2 years of java. It seems so different but im getting there. my lecturer is a lovely guy but any time i ask a question as to why something is that way or this way. he just responds "because it is". Theres lots of comments in the code below with a few random questions, but the main problem ...

set default_url_options on initialize

I need to force the host in one of the environments in my rails app. I've can get the override to work by including def default_url_options(opts={}) opts.merge({:host => 'stg.my-host.com'}) end in app/controllers/application.rb But is there a way to set this on initialize, preferably in a config/environments/... file? I'd li...

Is there a way to make a C++ struct value-initialize all POD member variables?

Suppose I have a C++ struct that has both POD and non-POD member variables: struct Struct { std::string String; int Int; }; and in order for my program to produce reproduceable behavior I want to have all member variables initialized at construction. I can use an initializer list for that: Struct::Struct() : Int() {} the p...

Value initialization and Non POD types

An hour ago I posted an answer here which according to me was correct. However my answer was downvoted by Martin B. He said You're just lucky and are getting zeros because the memory that i was placed in happened to be zero-initialized. This is not guaranteed by the standard. However after reading Michael Burr's answer here and try...

Python: how can I initialize my empty objects ?

how can initialize empty objects in python ? I need to initialize my class members (for examples tk.frames, vtk visualizations etc) thanks ...

const conflicting

Hello, I have the following class class node { public: node() { } node(const node&); node(luint inID) { ID = inID; } ~node() { neighbors.clear(); } node& operator=(const node&); void addNeighbor(luint); void addNeighbor(const std::vector<luint>& ); void setID(luint inID) { ID = inID; } luint getID() ...

How to initialize an NSData in order to store MAX_SIZE_BUFFER bytes ?

Hi, I have just realized I lost 30 minutes searching in Xcode NSData Class reference how to do this in objc (sorry I explain this in C as this in the only language which comes without thinking too much): #define MAX_SIZE_BUFFER 500 byte *ptr; ptr = malloc(MAX_SIZE_BUFFER * sizeof(byte)); memset(ptr, 0, MAX_SIZE_BUFFER); I started to ...