initialization

Detecting nulls in Excel VBA

In a program i'm currently working on i've created a user defined type to contain some data that i'll later use to populate my form. i'm using an array of that user defined type and as i pull more data from a offsite server i'm resizing the array. So in order to make my program easier to digest i've starting splitting it into subroutin...

method running on an object BEFORE the object has been initialised?!

#include <iostream> using namespace std; class Foo { public: Foo(): initialised(0) { cout << "Foo() gets called AFTER test() ?!" << endl; }; Foo test() { cout << "initialised= " << initialised << " ?! - "; cout << "but I expect it to be 0 from the 'initialised(0)' initialiser on Foo()" << endl; cout << "this method test(...

Will the initialization list always be processed before the constructor code?

Will the initialization list always be processed before the constructor code? In other words, will the following code always print <unknown>, and the constructed class will have "known" as value for source_ (if the global variable something is true)? class Foo { std::string source_; public: Foo() : source_("<unknown>") { std::c...

Initiate a class by calling a function that returns an instance of that class - PHP?

class foo(){ function bar() { $classInstance = $this->createClassInstance($params); $result = $classInstance->getSomething(); } function createClassInstance($params) { require 'path/to/class.php'; $myClass = new Class; $myClass->acceptParams($params['1']); $myClass->acceptMoreParams($params[...

Setting an instance variable in initialize

Is it possible to assign a value to an instance variable during an initialize class method? I'm declaring a number of arrays, then creating an array of arrays, then assigning it to self.months, which is an instance variable. Why does this not work, and how can I accomplish this? +(void)initialize { // ..... NSArra...

C++ empty-paren member initialization - zeroes out memory?

I originally wrote some code like this: class Foo { public: Foo() : m_buffer() {} private: char m_buffer[1024]; }; Someone who is smarter than me said that having the m_buffer() initializer would zero out the memory. My intention was to leave the memory uninitialized. I didn't have time to discuss it further, but it piqued ...

setattr with kwargs, pythonic or not?

I'm using __init__() like this in some SQLAlchemy ORM classes that have many parameters (upto 20). def __init__(self, **kwargs): for k, v in kwargs.iteritems(): setattr(self, k, v) Is it "pythonic" to set attributes like this? ...

Overriding a setter method, and getting info out

I have a setter method (setMinimumNumberOfSides) that I want to override after using synthesize. In it, I'm putting in a constraint on the instance variable to make sure the int is within certain bounds. Later in a custom init method, I'm setting another instance variable (numberOfSides), but I need to make sure minimumNumberOfSides an...

Default values in a C Struct.

I have a data structure like this: struct foo { int id; int route; int backup_route; int current_route; } and a function called update() that is used to request changes in it. update(42, dont_care, dont_care, new_route); this is really long and if I add something to the structure I have ...

Determine array size in constructor initializer

In the code below I would like array to be defined as an array of size x when the Class constructor is called. How can I do that? class Class { public: int array[]; Class(int x) : ??? { } } ...

Handling a class with a long initialization list and multiple constructors?

I have a (for me) complex object with about 20 data member, many of which are pointer to other classes. So for the constructor, I have a big long, complex initialization list. The class also has a dozen different constructors, reflecting the various ways the class can be created. Most of these initialized items are unchanged between each...

How can I best initialize constants from a database or servlet context?

We have constants declared in an interface in our application like this. public interface IConstants { public static final String FEVER="6"; public static final String HEADACHE="8"; } We now want to populate these constants values (6 and 8) from the database (or application servlet context). The database values stored in a lo...

C++ Initializing a Static Stack

Hello. I have some questions about initializing a static collection. Here is an example I coded that seems to work: #include <stack> #include <iostream> using namespace std; class A { private: static stack<int> numbers; static stack<int> initializeNumbers(); public: A(); }; A::A() { cout << numbers.top() <<...

Why do I have to assign all fields inside an struct's constructor?

Duplicate: Why Must I Initialize All Fields in my C# struct with a Non-Default Constructor? If in the constructor of an struct like internal struct BimonthlyPair { internal int year; internal int month; internal int count; internal BimonthlyPair(int year, int month) { this.year = year; t...

Can I guarantee the order in which static initializers are run in Java?

I have a Set class (This is J2ME, so I have limited access to the standard API; just to explain my apparent wheel-reinvention). I am using my set class to create constant sets of things in classes and subclasses. It sort of looks like this... class ParentClass { protected final static Set THE_SET = new Set() {{ add("one"); ...

How to perform common post-initialization tasks in inherited Python classes?

The initialization process of group of classes that share a common parent can be divided into three parts: common part1, class-specific part, common part2. Currently the first two parts are called from the __init__ function of each child class, but the second common part has to be called separately For example: class BaseClass: def ...

WinForms Control - Action after it is fully initialized

To a WinForms control, I would like to add a handler after the container has initialized the control (or even better, after the parent has initialized all contained controls). Reason: The custom control has an option to trigger an action automatically. It should also trigger when this option is first enabled. However, at this point, ot...

Creating a byte array using the long datatype?

Most of the time when we read the file stream into a byte array, we would write the following code:- Dim inputStream As New System.IO.FileStream(filePath, IO.FileMode.Open) Dim fileLength As Integer= CType(inputStream.Length, Integer) Dim input(fileLength) As Byte Using inputStream inputStream.Read(input, 0, fileLength) End U...

Deploying a WebService in glassfish with init parameters

I've created a WebService using the JAX-WS API. This service runs without any problem using an Endpoint class. main(String args[]) { (...) MyService service=new MyService(); service.setParam1("limit=100"); service.setParam2("hello"); service.setParam3("max-value=10"); Endpoint endpoint = Endpoint.create(service); endpoint.publish("http:...

Initialisation of keyword args in Python

Why does the following: class A(object): def __init__(self, var=[]): self._var = var print 'var = %s %s' % (var, id(var)) a1 = A() a1._var.append('one') a2 = A() result in: var = [] 182897439952 var = ['one'] 182897439952 I don't understand why it is not using a new instance of a list when using optional keyword arg...