constructor

C# Constructor Problem When Using Generics

Please see an example of my code below: CODE UPDATED public class ScrollableCheckboxList { public List<ScrollableCheckboxItem> listitems; public ScrollableCheckboxList<TModel>(IEnumerable<TModel> items, string valueField, string textField, string titleField) where TModel : class { listitems = new List<ScrollableChe...

BLL returning the right Type of an instance

I have a class "Artikel" and there i write some Business Logic. I also have a class "tArtikel" which is a type. In my class "Artikel" I work with "tArtikel" and returns are of that type. Now when i instantiate an "Artikel" i want it to be of type "tArtikel", so what i tried in my code is: public tArtikel Artikel() { ...

Static constructors cause a performance over head ?

Recently read in a article on dotnetpearls.com here saying that static ctors take a substantial amount of perfomance hit. Could not fathom why ? ...

StructureMap - Injecting a dependency into a base class?

In my domain I have a handful of "processor" classes which hold the bulk of the business logic. Using StructureMap with default conventions, I inject repositories into those classes for their various IO (databases, file system, etc.). For example: public interface IHelloWorldProcessor { string HelloWorld(); } public class HelloWor...

constructor in objective c

HI, I have create my iPhone apps but i have a problem. I have a classViewController where i have implemented my program. I must alloc 3 NSMutableArray but i don't want do it in a grapich methods. There isn't a constructor like java for my class? Thanks so much and sorry for my english XP // I want put it in a method like constructor jav...

Const parameter at constructor causes stackoverflow

I've found this strange behavior with VS2005 C++ compiler. Here is the situation: I cannot publish the code, but situation is very simple. Here is initial code: it work perfectly class Foo { public: Foo(Bar &bar) { ... } } The constructor implementation stores a reference, setup some members... indeed nothing special. If ...

Init var without copy constructor

Hello, I have some class(Window) without copy constructor (it's private). I can't understand how to init var of this class in my own class: class MyClass { Window obj; // Hasn't copy constructor public: void init() { obj = Window(/* constructor params */); // [error] obj(/* constructor params */); // ...

Kohana 3 - Constructor

I attempted to use public function __construct() { } but got the error ErrorException [ Strict ]: Creating default object from empty value. The reason behind this is that I use a controller that is protected for logged in users only, I don't want to have to call $this->protect(); from every action in the controller. Hence my a...

C++: Static variable inside a constructor, are there any drawbacks or side effects?

What I want to do: run some prerequisite code whenever instance of the class is going to be used inside a program. This code will check for requiremts etc. and should be run only once. I found that this can be achieved using another object as static variable inside a constructor. Here's an example for a better picture: class Prerequisi...

Custom constructors for models in Google App Engine (python)

I'm getting back to programming for Google App Engine and I've found, in old, unused code, instances in which I wrote constructors for models. It seems like a good idea, but there's no mention of it online and I can't test to see if it works. Here's a contrived example, with no error-checking, etc.: class Dog(db.Model): name = db....

Return Statement in JS Constructors

What is the effect of a return statement in the body of JavaScript function when it's used as a constructor for a new object(with 'new' keyword)? ...

call_user_function_array() and __construct

I'm working on a simple framework, and I'm having a slight problem. I'd like to use call_user_function_array() to pass parameters to a function. That's fine, except the function I want to pass it to is __construct. I can't create an instance of an object with cufa(), and by instantiating an object, and then using cufa to call that instan...

Problem accessing base member in derived constructor

Given the following classes: class Foo { struct BarBC { protected: BarBC(uint32_t aKey) : mKey(aKey) mOtherKey(0) public: const uint32_t mKey; const uint32_t mOtherKey; }; struct Bar : public BarBC { Bar(uint32_t aKey, uint32_t aOtherKey) ...

Default Struct Initialization in C++

Say I have a struct that looks like this (a POD): struct Foo { int i; double d; }; What are the differences between the following two lines: Foo* f1 = new Foo; Foo* f2 = new Foo(); ...

how to write a constructor...

is that correct to write a constructor like this? class A { A::A(const A& a) { .... } }; if yes, then is it correct to invoke it like this: A* other; ... A* instance = new A(*(other)); if not, what do you suggest? Thanks ...

Factory vs instance constructors

I can't think of any reasons why one is better than the other. Compare these two implementations: public class MyClass { public MyClass(string fileName) { // some code... } } as opposed to: public class MyClass { private MyClass(){} public static MyClass Create(string fileName) { // some code....

Any way to _not_ call superclass constructor in Java?

If I have a class: class A { public A() { } } and another class B extends A { public B() { } } is there any way to get B.B() not to call A.A()? ...

How to avoid GeneratedSerializationConstructorAccessor problems?

We have a Java App that receives SOAP requests, and after a lot of requests we notice that the GC stops the world to unload a lot of GeneratedSerializationConstructorAccessor classes. This is a big performance impact. Does anyone know how to avoid this or at least significantly reduce the count of GeneratedSerializationConstructorAccess...

C++ Constructor Parameters Question

Hi, I'm learning C++. I have a simple class named GameContext: class GameContext { public: GameContext(World world); virtual ~GameContext(); }; To initialize a GameContext object, I need a World object. Should the GameContext constructur take a pointer to a World object (World*), the address to a World object (&...

Use Moq to mock Constructor?

I have such a set of Constructors: public BusinessObjectContext() : this(CloudStorageAccount.FromConfigurationSetting("DataConnectionString").TableEndpoint.ToString(), CloudStorageAccount.FromConfigurationSetting("DataConnectionString").Credentials) {} public BusinessObjectContext(string dataConnectionString) : ...