constructor

How to pass arguments to stage instances in ActionScript 3?

I have an instance on my stage that I dragged from my library at design time. This instance links to a custom class who's constructor takes an argument. package { import flash.display.MovieClip; import flash.media.Sound; public class PianoKey extends MovieClip { var note:Sound; public function PianoKey...

How to pass an object to the constructor through castle windsor?

Hi, I am building an object through castle windsor and my constructor accepts an argument of a custom type. How do I pass it to my object. public class ArgumentClass { int value1; string value2; } public interface IInterface { } public class CClass : IInterface { public CClass(ArgumentClass arg) { } } All my configuration is...

Simple Handmade PHP Template Engine not working! Help Please

These are the class definitions <?php abstract class MyTemplate { protected $arrayOfSpaces; protected $arrayOfVariables; protected $output; protected abstract function __construct(); function outputHTML(){ echo $output; //Apparently, the problem is HERE. <<<<>>>>> } } class MyTemplateMain extends MyTemplate { ...

Java memory leak, destroy/finalize object

Hi! I am experiencing a memory leak with a code similar to the one below (it's a simulation with different inputs at every loop). The problem The object Object_XXX is quite complex, with connections to databases and other objects populated with data from databases aswell. for(int i=0; i<MAX; i=i+1){ Class_XXX Object_XXX ...

Stuff a class with user-defined constructors into a union

class Foo { Foo(int val) { /* Do some initialization */ } Foo() { /* Do nothing */ } }; union Bar { Foo foo; }; That code generates this error: error C2620: member 'Bar::foo' of union 'Bar' has user-defined constructor or non-trivial default constructor I understand why you'd throw that error if the constructor actually d...

scala: How to get the class in its own constructor

I need access to the Class of the object being constructed in its own constructor (for various detailed reasons I don't think are relevant to my question). I want something like this class Foo(val i:Int) class Bar extends Foo(this.getClass.getName.length) val b = new Bar println(b.i) to print 3 ("Bar".length). But it doesn't. If th...

C++ restrict implicit construct to specific value

hello Suppose: struct P { P(int v); }; int v; P p = 0; // allow P q = v; // Fail at compile time How can achieve that? any template trick? I am trying to write allocator which has special pointer properties. unfortunately std implementation uses implicit conversion from int to NULL pointer: { return __n != 0 ? _M_impl.allocat...

Why is there no call to the constructor?

This code doesn't behave how I expect it to. #include<iostream> using namespace std; class Class { Class() { cout<<"default constructor called"; } ~Class() { cout<<"destrutor called"; } }; int main() { Class object(); } I expected the output 'default constructor called', but I did not...

Injecting code in a C++ base class constructor

I'm deriving a class which is available from a C++ library, and the constructor of my subclass will only work properly when I execute some code before the base class constructor gets called. (Yes, I know, bad design, but I cannot influence how the library which I'm using works.) If the base class constructor takes arguments, doing this ...

Are constructors optional in Java or what?

I'm a C# programmer trying to hack at a Java project. Here's an anonymized extract from our production code. It works (I think). Note that this is the whole class. public class Y extends X { public Z m_Z; protected void readCustomData (CustomStream reader, boolean forUpdate) throws IOException, FTGException { super.readCu...

Make a constructor warn the developer of improper value?

Private _bgWorker As BackgroundWorker = Nothing Private _bgWorkerMessage As String = String.Empty Private _bgPercentComplete As Integer = 0 Private _dictQueries As Dictionary(Of String, String) = New Dictionary(Of String, String) Public Sub New() _dictQueries.Add("IPB", "") _dictQueries.Add("Figure", "") _dictQueries.Add("Pa...

What's the reason of using implicit/explicit convertions instead of constructors?

An example would be: XNamespace ns = "my namespace" Why not?: XNamespace ns = new XNamespace ( "my namespace" ) What's the idea behind using implicit/explicit convertions instead of constructors? Convenience? Is there a guideline for this? ...

Constructors cannot be virtual, why? Not a dupe

Possible Duplicate: Why do we not have a virtual constructor? I know this has been asked before but I didn't understand the complex technical words used in the other answers. I read on a community the reason that constructors cannot be virtual is The ‘virtual’ mechanism works on a logically complete (completely constructe...

Any problem with doing the main work of a class in its constructor?

I have always felt that in general the main work of a class should be done in its instance methods, while the constructor should only get the instance into a usable inital state. But I find that in practice there are situations where it seems to make more sense to put essentially all the actual work into the constructor. One example: I...

Call a base class constructor later (not in the initializer list) in C++

I'm inheriting a class and I would like to call one of its constructors. However, I have to process some stuff (that doesn't require anything of the base class) before calling it. Is there any way I can just call it later instead of calling it on the initializer list? I believe this can be done in Java and C# but I'm not sure about C++. ...

Building Constructors for RPG game in Objective C

I have a character model class which has this structure: @interface CharacterModel : NSObject { // parent of this character CharacterModel *parentChar; // basic details NSString *fname, *sname, *nick; NSString *char_type; // categories of characters: dwarf, etc // health int health; // cash double...

Handling iDisposable in failed initializer or constructor

Is there any nice pattern in .Net for ensuring that iDisposable fields owned by an object will get disposed if an exception is thrown during construction, possibly during a field initializer? The only way to surround field initializers in a Try/Catch block is if the block is outside the call to the constructor, which will make it rather...

implicit cast through contructor with multiple arguments

If I have these 2 constructors for MyClass: MyClass(int n1); MyClass(int n1, int n2); and an overloaded (non-member) operator+: MyClass operator+(MyClass m1, const MyClass& m2); This enables me to write code like this: MyClass m; 5 + m: which I guess uses implicit cast through the defined constructor, correct? Is there anyway t...

General reasons not to deal with Document's and Element's prototype

Are there general reasons not to deal with Document's and Element's prototype? I like to create my own little framework, because my current project doesn't need the mass of features of the existing frameworks. I don't need to support browsers which don't support Element/Document-constructor and also will not execute scripts that are no...

C# Instance Constructor vs Static Constructor

What are the differences between the two? I've only used one kind of constructor and I believe it's the static constructor. Only familiar with C++ and Java. ...