initialization

Objective-C Multiple Initialisers

I have a simple question about creating multiple initialisers within an objective-c class. Basically I have a class that represents a single row in my database (users). I currently have an initialiser which initialises the class based upon the users UserID (which is also the primary key within the database), when passed the UserID the cl...

Objective C -- initializing inherited variables of a subclass object

I have a class MyClass. I am exaggerating here, but let's say MyClass has 1000 instance variables. I then create a subclass called MySubClass with all the instance variables MyClass has, plus one more. Question: given an object MyObj of class MyClass, is there an easy way to create a corresponding object MyDerivedObj of class MySubC...

Initializing fields in inherited classes

What's the best way to initialize constants or other fields in inherited classes? I realize there are many syntax errors in this example, but this is the best example to explain clearly what I am trying to do. public abstract class Animal { public abstract const string Name; // #1 public abstract const bool CanFly; public abstract...

initialize java HashSet values by construction

Hello, I need to create a Set with initial values. Set<String> h = new HashSet<String>(); h.add("a"); h.add("b"); Is there a way to do it in one command? Thanks ...

Initialising a static variable in Objective-C category

I was trying to create a static variable to store a dictionary of images. Unfortunately, the best way I could find to initialise it was to check in each function that used the variable. Since I am creating this variable inside a category, I can't just initialise it inside the initialiser. Is there a neater way of initialising navigationB...

Dependency on Derived class constructor problem

Hello Group, I am working on a legacy framework. Lets say 'A' is the base-class and 'B' is the derived class. Both the classes do some critical framework initialization. FWIW, it uses ACE library heavily. I have a situation wherein; an instance of 'B' is created. But the ctor of 'A' depends on some initialization that can only be perf...

how to get Application_Start (in Global.asax.cs) to be called before requests in asmx web service on IIS 6.0

Hello, in my ASMX WS Application_Start is called when 1st request arrives. It's kind of too late then for me. Is there any way to get it called when iisreset is done? In http://stackoverflow.com/questions/1820770/what-is-the-right-way-to-spawn-thread-for-database-io-in-asmx-web-service I asked about preloading system data and the guys ...

Why my Objective-C object doesn't want to be instantiated ?

I've got a problem (in Objective-C/iPhone dev) since more than one week, so I'd be really grateful if someone can help me out. When I instantiate an object from a class that I've written, it returns me nil, but when I launch the debug mode I actually see in the init method that the attributes of self are correctly initialized and it see...

Can't initialize an NSMutableData with an NSData (which contains a png)

Hello, there is a error in my iPhone app. I use the CameraPicker to make and get a picture and then I give it to my methode sendPhoto, which will send the photo to TweetPhoto. Everything works great until I initialize an NSMutableDate with NSData. Here is the code: - (void)imagePickerController:(UIImagePickerController *)picker didFinis...

where is the better place to do initialization work in winform?

In the Load event or in the constructor after the InitializeComponent()? or doesn't matter at all? ...

How to keep an NSArray available to all methods when programming for the iPhone.

Hello. I am making an iPhone app that uses a few NSArrays. Right now I have to generate the arrays in each method. I know there has to be an more efficient way of doing this, like having the NSArrays created during initialization and then being available to all methods after that. The problem is, that when I create the NSArrays in th...

Literal initialization for const references

How does the following code work in C++? Is it logical? const int &ref = 9; const int &another_ref = ref + 6; Why does C++ allow literal initialization for const references when the same is not permitted for non-const references? E.g.: const int days_of_week = 7; int &dof = days_of_week; //error: non const reference to a const objec...

What is correct way to initialize a static member of type 'T &' in a templated class?

I'm playing around with an eager-initializing generic singleton class. The idea is that you inherit publicly from the class like so: class foo : public singleton<foo> { }; I've learned a lot in the process but I'm stuck right now because it's breaking my Visual Studio 2008 linker. The problem is with the static instance member and/or ...

Adding callbacks for model classes in separate file (RoR)

I have a Message model class (which inherits from ActiveRecord::Base). For a particular deployment, I would like to have a separate file which modifies Message by adding a callback. So, instead of doing: # app/models/message.rb class Message < ActiveRecord::Base before_save :foo def foo puts 'foo!' end end I would like to b...

Cocoa: Calling a method from AppDelegate.m

In order to better understand the startup, event queue, and methods within my application I'm trying to write a program that does two things: Play a beep at the startup and every time the user hits a button. So far it only plays when the user hits the button. I know there may be multiple ways to get the startup beep to play, but in ord...

Initializing Constant Static Array In Header File

Hi, I have just found out that the following is not valid. //Header File class test { const static char array[] = { '1', '2', '3' }; }; Where is the best place to initialize this? Thanks in advance; ...

How do I initialize an object of a class?

My code is something like: public class Foo { public int a; Bar[] bar = new Bar[10]; a = bar[0].baz; } public class Bar { public int b; public Bar () { //I tried doing away with this constructor, but that didn't //fix anything b = 0; } public int Baz () { //do somthing ...

Declare in C == define in C++ ?

Possible Duplicate: What is the difference between a definition and a declaration? Is it correct that to declare in C is equal to define in C++? int a; /* to declare variabel a in C */ int b = 2; /* to declare and initialize in C */ int c; // to define in C++ int d = 4; // to define and initialize in C++ ...

How can I best deal with problems when initializing a model in an iphone app?

So assume I have a class that has an init method that does something like... grabs some data off the net in xml format and parses it to initialize some of its properties. My concern is how should I handle the case where the network is down or the xml data my object receives is bad? Normally in C i would use return values to indicate an...

NSXMLDocument's initWithContentsOfURL is sometimes really slow on loading a URL's contents

As the title says, some URLs take less than a second to load in the browser, but in my cocoa app, running the following line repeatedly results in initWithContentsOfURL sometimes taking up to 30 seconds to load the URL. What may be the source of this problem? I'm calling it like this: NSXMLDocument* aDoc = [[NSXMLDocument alloc] initWi...