initialization

How to store a factory used in a derived class to initialize its base class?

Assuming you had some kind of factory-created resource that would still belong to the factory after construction like this: public class Resource : IDisposable { public void Dispose() { /* ... */ } } public class ResourceManager : IDisposable { public Resource Load() { /* create resource and add to list */ } public void Dispose()...

C# How to initialize WebService.

Is there a possibility to initialize a WebService. I'm searching for a method that runs only during first call to WebService. Is there something like it in .Net ? ...

How does inheriting from NSObject work?

There are a couple of things about Objective-C that are confusing to me: Firstly, in the objective-c guide, it is very clear that each class needs to call the init method of its subclass. It's a little bit unclear about whether or not a class that inherits directly from NSObject needs to call its init method. Is this the case? And if...

C# Automatic Properties - Still null after +=?

This seems like a bug to me... I accept that automatic properties, defined as such: public decimal? Total { get; set; } Will be null when they are first accessed. They haven't been initialized, so of course they are null. But, even after setting their value through +=, this decimal? still remains null. So after: Total += 8; Tot...

Assigning to self in Objective-C

I'm from the C++ world so the notion of assigning this makes me shudder: this = new Object; // Gah! But in Objective-C there is a similar keyword, self, for which this is perfectly acceptable: self = [super init]; // wait, what? A lot of sample Objective-C code uses the above line in init routines. My questions: 1) Why does assign...

Cannot use MySqlConnection after initialization. Why?

I downloaded MySql Connector/NET, and set it as a reference in my project. I added the using MySql.Data.MySqlClient; to my code. Now I tried initializing a connection like this: MySqlConnection test = new MySqlConnection(Utilities.GenerateMySqlConnectionString("localhost", "test", "root", "")); However I cannot use this object later....

VS2008 C++ Compiler error?

this compiles :-) string name; name = 1; this does not: string name = 1; any thoughts? I know that this is wrong. . . that is not the point. The first gives a smiley face. ...

UIViewController not working for the first time

MyController *myViewController = [[MyController alloc] initWithNibName:@"myView" bundle:nil]; The nib file myView.nib has 2 uiimageviews and 2 uilabels. When I first init myViewController, all the 4 subviews are set as 0x0. The second time I dont get such a behavior. ...

NSManagedObject subclass outside of managed object as a normal object

Hi all, I have an entity object Country with country name and country code. It is a subclass of NSManagedObject and I am using it with core data model to store its value to a persistent store. I have a place where the same Country object will used as a normal object i.e. I will use it to store some temporary country name. For that I ...

What is the start up/initialization procedure when an iPhone app is started ?

I would elaborate it as follows : In what order are the different objects and nib files instantiated/initialized ? My understanding is as follows: 1) UIMainApplication function loads the main .nib file specified in info.plist. 2) This .nib file instantiates the Delegate object. 3) When the appDidFinishLoading method runs, it generall...

C++ pointer to class

can anyone tell me whats the difference between Display *disp = new Display(); and Display *disp; disp = new Display(); and Display* disp = new Display(); and Display* disp(new Display()); Regards, Zeeshan Also, i am very new to c++, just trying to figure out a few things. If you thing my questions are smelly, let me kno...

Meaning of new Class(...){{...}} initialization idiom

What does {{...}} block mean in the following code? class X { private Y var1; private X() { Z context = new Z(new SystemThreadPool()) {{ var1 = new Y(); }}; } } ...

how do i initialize the money gem?

I have a new gem I'm playing with, but I'm not sure where to put it so that it is initialized, but that I don't have to do it each and every time I use my method which uses it. def self.get_rate(from, to, amount) Money.default_bank.fetch_rates #<---------------- Here it is... if to == "USD" or from == "USD" rate = Mon...

Initializing static array of strings (C++)?

I can't for the life of me figure out how to do this properly. I have a class that needs to store some constants (text that corresponds to values in an enum type) - I have it declared like this (publicly) in my class: const static char* enumText[]; And I'm trying to initialize it like this: const char* MyClass::enumText[] = { "A", "...

Can PHP instantiate an object from the name of the class as a string?

Is it possible in PHP to instantiate an object from the name of a class, if the class name is stored in a string? ...

How to initialze an array after dynamic memory allocation?

I have a function that returns an array of different lengths based on a table lookup. I am malloc'ing required memory for it inside the function but then how can I fill the array from its pointer? The compiler is throwing same error for both of my tries (commented lines). Please help! int lookup(const char *name, float *factors) { i...

How do array semantic initializers work in C#?

in C# 3, initializers were added. This is a great feature. However, one thing has me confused. When you initialize class, you typically have to specify the member variable or property you are initializing. For example: class C { public int i; } public void blah() { C c = new C() { i = 1 }; } Array semantics have been in C# si...

Should properties do nontrivial initialization?

I have an object that is basically a Python implementation of an Oracle sequence. For a variety of reasons, we have to get the nextval of an Oracle sequence, count up manually when determining primary keys, then update the sequence once the records have been inserted. So here's the steps my object does: Construct an object, with a ke...

How to initialize a ByteBuffer if you don't know how many bytes to allocate beforehand?

Is this: ByteBuffer buf = ByteBuffer.allocate(1000); ...the only way to initialize a ByteBuffer? What if I have no idea how many bytes I need to allocate..? Edit: More details: I'm converting one image file format to a TIFF file. The problem is the starting file format can be any size, but I need to write the data in the TIFF to li...

Syntax for initializing a List<T> with existing List<T> objects

Hello, is it possible to initialize a List with other List's in C#? Say I've got these to lists: List<int> set1 = new List<int>() {1, 2, 3}; List<int> set2 = new List<int>() {4, 5, 6}; What I'd like to have is a shorthand for this code: List<int> fullSet = new List<int>(); fullSet.AddRange(set1); fullSet.AddRange(set2); Thanks in...