constructor

C# Constructor returning object with null fields

Strange thing is happening. My constructor returning object with null fields when one property value is 3 here is the constructor: public T_BR(BR br) { try { base.BR_ID = br.BR_ID; base.QT_ID = br.QT_ID; base.WWID = br.WWID; base.Date = br.Date; base.Ctg_ID = br.Ctg_ID; base.F_Ctg_...

Scope of object within an object in Java

I'm learning Java at the moment so I hope this question isn't too obvious. I come from another language which does not have garbage collection. In this other language I sometimes created objects in constructor and then deleted them in the destructor so I could use them for the entire life of the object. As a simplified example, I have a...

Is there a way to make a C++ struct value-initialize all POD member variables?

Suppose I have a C++ struct that has both POD and non-POD member variables: struct Struct { std::string String; int Int; }; and in order for my program to produce reproduceable behavior I want to have all member variables initialized at construction. I can use an initializer list for that: Struct::Struct() : Int() {} the p...

Memory leak during object construction in .NET

http://www.devx.com/tips/Tip/5573 The above post states that there will not be memory leak during object construction. How about the code below? Will this cause any memory leaks? I see that the memory usage for the sample application increases slowly (in task manager) even after forcing the GC collection. namespace WindowsFormsApplica...

C++: Is it possible to call an object's function before constructor completes?

In C++, is it possible to call a function of an instance before the constructor of that instance completes? e.g. if A's constructor instantiates B and B's constructor calls one of A's functions. ...

In Moose, how can I make a class's constructor return an instance of a subclass?

Possible Duplicate: How to have Moose return a child class instance instead of its own class, for polymorphism Suppose I have two related classes MyClass::A and MyClass::B that are both subclasses of MyClass. I would like the constructor for MyClass to take a filename, read the file, and based on the contents of the file, deci...

Copying an object using a constructor, Java

So lets say I want to make a deep copy of an object, but using its contsructor. So I have: public class PositionList { private Position[] data = new Position[0]; private int size = 0; public PositionList(PositionList other, boolean deepCopy) { if (deepCopy==true){ size=other.getSize(); for (int i=0;i<data.le...

Creating an object with a default constructor

So say I have this class: public class PositionList { private Position[] data = new Position[0]; private int size = 0; Now lets say I create a new PositionList object with the default constructor, so no arguments like so: PositionList list = new PositionList(); Does the new list object have any attributes? Does it have a si...

Deep copy of an object array

I want to make a deep copy of an object array using a constructor. public class PositionList { private Position[] data = new Position[0]; public PositionList(PositionList other, boolean deepCopy) { if (deepCopy){ size=other.getSize(); data=new Position[other.data.length]; for (int i=0;i<d...

C++ Inheritance Question

In the file test.cpp, I have this: template <typename T> class A { public: A(int a){}; virtual ~A(); private: }; class B : public A<int> { public: B(int a):A(a){}; virtual ~B(); private: }; int main() { return 0; } When I compile it, I get this: jason@jason-linux:~/Documents/ECLibrary$ g++ -g -Wall -Wextra -pedantic-err...

extends of the class with private constructor

Suppose we have the following code: class test { private test() { System.out.println("test"); } } public class One extends test { One() { System.out.println("One"); } public static void main(String args[]) { new One(); } } When we create an object One, that was originally called the...

WxWidgets: Troubling Callling wxFrame ConstructorE

Okay, I have run into a really bizarre problem. I have a wxWidgets program that has two frames, a main one, and a secondary one. The main one has a button that calls the second one to open. I had trouble with calling a derived class from the second wxframe's class, so I moved the declaration/implementation of the class to before the c...

C++ template constructor

Hello! I wish to have a non-template class with a template constructor with no arguments. As far as I understand, it's impossible to have it (because it would conflict with the default constructor - am I right?), and the workaround is the following: class A{ template <typename U> A(U* dummy) { // Do something } }; Maybe the...

How to force Java to reload class upon instantiation?

Background: I have a MainTest class that has many buttons, each of which instantiate a class that I am coding/testing. I want the code/test cycle for these classes to be quick, and see the effect of my changes quickly, a few times a minute. MainTest which is stable takes about 20 seconds to load, which would not be a problem had I not ne...

c#: beginners CLASS constructor problems

public class ElapsedTime { public int hours; public int minutes; public void ElapsedTime(int h, int m) { hours = h; minutes = m; } } from another event i am doing this: ElapsedTime BeginningTime = new ElapsedTime(); how would i initialize the h and m? when i try to do this: BeginningTime.Elap...

Multiple constructor with Python

I have a class A that can be generated from two different ways. a = A(path_to_xml_file) a = A(listA, listB) The first method has file path as an input to parse from XML file to get listA, and listB. The second method is given two lists. I can think of two ways to implement multiple constructor. What do you think? What method normall...

Implementing a protected parameterless constructor for unit testing

If I have a type with a big-old (lots of params) constructor, is it a valid approach to implement a protected parameterless constructor simply for the purposes of creating a derived "Fake" type to use for stubbing in unit tests? The alternative is to extract an interface, but this is not always desireable in a codebase you do not have f...

templated class with templated constructor (of other type)

Is it possible to have a templated class and also templating the constructor with some other type? something like this: template<typename T1> class Foo{ template<typename T2> Foo(T1 aBar, T2 dummyArgument){ bar = aBar; bytesOfT2 = sizeof(T2); }; int bytesOfT2; T1 bar; }; is this possible? and if s...

what is an initialization blocks

we can put a code in constructor/method/init block. What is the use of init block? Is it necessary that every java pgm must have that? ...

Constructing associative containers

I was convinced (until I just tried it a moment ago) that it was possible to instantiate an associative container with array style notation. For example, std::set< int > _set = { 2, 3, 5 }; This isn't the case but I am wondering if there is any other way of bulk initialising a container in the constructor like this? ...