initialization

Is there an equivalent to a member-wise initialization list in PHP?

I'd like to start with a little background, in case anyone has any better ideas for design. I'm looking to create a database class that connects to a database at construction. I would use functions to call the database, to get what I want. The database connection would be closed at destruction. Since I'm connecting in construction, I'd...

What is the "correct" way to initialize a C# delegate?

C# delegates have always been difficult for me to grasp and so I was very happy to stumble across logicchild's article on The Code Project web site titled "C# Delegates: Step by Step". He has a very succinct way of explaining C# delegates and I can recommend it to you. However, in trying out the examples, I see that are two ways to initi...

Is there a way to statically-initialize a dynamically-allocated array in C++?

In C++, I can statically initialize an array, e.g.: int a[] = { 1, 2, 3 }; Is there an easy way to initialize a dynamically-allocated array to a set of immediate values? int *p = new int[3]; p = { 1, 2, 3 }; // syntax error ...or do I absolutely have to copy these values manually? ...

Convert String to int array

I have an int array that holds a single digit in each index so that once printed out, it displays a long number. Ex: digit = {1, 2, 3, 4, 5} would look like 12345. I have a method that takes a string as parameter and puts the numbers it gets from the string into the digit array. It looks like this: digit = new int [50]; for (int i =...

call void on showing the view

is there something that can call a -(void) every time a view shows. I am rotating between two views, so when i go to the second view and then return to the first view I want a void to be called automatically from the first view I've try to do this with -(void)viewWillAppear:(BOOL)animated and - (void)viewDidLoad by putting a NSLog in th...

C++: automatic initialization

I find it sometimes annoying that I have to initialise all POD-types manually. E.g. struct A { int x; /* other stuff ... */ A() : x(0) /*...*/ {} A(/*..*/) : x(0) /*...*/ {} }; I don't like this for several reasons: I have to redo this in every constructor. The initial value is at a different place than the variable...

Constructor for structs in C

Given: struct objStruct { int id; int value; }; typedef struct objStruct Object; Is there a shortcut to allocate and initialize the object, something like a C++ constructor? It could even be a preprocessor macro. Whatever makes the code shorter and more readable than this: Object *newObj = malloc(sizeof(Object)); // successf...

Making all variables in a scope global or importing a module inside another module

I have a package with two modules in it. One is the __init__ file, and the other is a separate part of the package. If I try from mypackage import separatepart, the code in the __init__ module is run, which will run unneeded code, slowing down the importing by a lot. The code in separate part won't cause any errors, and so users should b...

Type initializer threw an exception

This class is throwing an exception. It doesn't show me the exact line number, but it sounds like it's occurring in the static constructor: static class _selectors { public static string[] order = new[] { "ID", "NAME", "TAG" }; public static Dictionary<string, Regex> match = new Dictionary<string, Regex> { { "ID", new Re...

How do I initialize a std::set comparator?

I need to initialize some comparator of the new data type TType based on std::set with some object o of another class Object: typedef std::set <unsigned int, sortSet(o)> TType This declaration is otside the class (in header file). At the time of the declaration this object does not have to exist, it will be created later. class sortS...

iPhone App view fails to load in iPad but loads in iPhone simulator

I am simulating an "iPhone-only" app in iPad. The binary simulates fine in the iPhone simulator, but when attempting to simulate in the iPad, the initial background image appears, but then the screen just goes black. (Xcode v4.1, SDK 4.1) The app has only one view, which is controlled by a single custom UIViewController. (SoloViewContro...

Type conversion for function parameters

class A{ }; class B{ public: B(); B(const &A); }; void foo(A &a){ } int main(){ B b; foo(b); //error: invalid initialization of reference of type ‘A&’ from expression of type ‘B’ return 0; } In the above code, I have a compilation error error: invalid initialization of reference of type ‘A&’ from expression of ty...

Where can I use cookies in Ruby on Rails

I'm using controller's initializer to setup stuff that I will need. def initialize super() a = cookies[:a] # EXCEPTION end However I can't use cookies because it's null, the system hasn't read them from the header yet. The same problem was with ASP.NET MVC, where I couldn't access the cookies in the constructor, but I could acce...

Why use an initialization method instead of a constructor?

I just got into a new company and much of the code base uses initialization methods instead of constructors. struct MyFancyClass : theUberClass { MyFancyClass(); ~MyFancyClass(); resultType initMyFancyClass(fancyArgument arg1, classyArgument arg2, redundantArgument arg3=TODO); // several ...

c++ initialize array in constructor without using default constructor or assinment

Consider: struct A { A (int); A (const A &); }; struct B { A foo [2]; B (const A & x, const A & y) : foo {x, y} /* HERE IS THE PROBLEM */ {} }; I was expecting this to work since I'm using C++0x support in GCC4.3, which allegedly supports initialiser lists. No joy. I have a class A which has no default constructor. This is...

Iphone: Is this a bad Idea? Memory Management/Leak Issue

I have a class, that basically manages core data. inserts deletes and updates data. I initialize this class like so - (id)init { self = [super init]; if (self) { self.itemList = [NSDictionary dictionaryWithObjectsAndKeys: // <== LEAKS ITEMURL1, KEY1, ITEMURL2, KEY2, ...

What are primitive types default-initialized to in C++?

When I use an initialization list: struct Struct { Struct() : memberVariable() {} int memberVariable; }; the primitive type (int, bool, float, enum, pointer) member variable is default-initialied. Is the value it gets implementation defined or is it the same for all implementations? ...

Scala initialization behaviour

Please look at the following code. trait MyTrait { val myVal : String } class MyClass extends MyTrait { val myVal = "Value" } class MyClass2(val myVal: String) extends MyTrait Why does the initialization order differ in case of MyClass and MyClass2? The constructor of MyClass will be as MyClass() { MyTrait$class.$init$(this); ...

How to emulate/inherit array initialization syntaxin c#?

I am building a matrix class ( I am aware one exists), I'm thinking about initialization. Currently one of the initializations is double[,] data; public Matrix(double[,] data) { if (data.GetLength(0) == 0 || data.GetLength(1) == 0) { throw new ArgumentException(); } this.data = (double[,])(data.Cl...

opening a new window counteracts my "enforce_auth"

Hello, On my social network. There are "home" links that take you to the appropriate index if you are signed in or out. There is a "index.php", that if you are browsing the site signed out, it takes you there, and if signed in, and hit "home" it takes you to "index_signedIn.php" This is working fine for me. The problem is, when I close ...