constructor

Calling a constructor to re-initialize object

is it possible to re-initialize an object of a class using its constructor? ...

What is a copy constructor in C++?

On page 6 of Scott Meyers's Effective C++, the term 'copy constructor' is defined. I've been using Schiltdt's book as my reference and I can find no mention of copy constructors. I get the idea but is this a standard part of c++? Will such constructors get called when a pass a class by value? ...

Python: creating class instance without calling initializer

Is there any way to avoid calling __init__ on a class while initializing it, such as from a class method? I am trying to create a case and punctuation insensitive string class in Python used for efficient comparison purposes but am having trouble creating a new instance without calling __init__. >>> class String: def __init__(self...

Why can't I overload constructors in PHP?

I know it can't be done, well I hope it can't or my Google skills have failed me. But my annoyance is beyond that now, I have abandoned all hope of ever being able to overload my constructors in PHP, so what I'd really like to know is why. Is there even a reason for it? Does it create inherently bad code? Is it widely accepted language ...

How to validate 'instance' in a Django form constructor MyForm(instance=myInstance)

I have the data stored in a format different from the display format. I've already worked out the form-to-db conversion in the clean_weight() method of the form, this gives me access to properly format data before saving it. Now I pretend to manipulate the instances weight before the form is displayed but I fail to see a good place to...

Declaring a variable as a "Class" datatype, without calling the "Class" constructor?

Forgive me if I'm just blatantly missing something, but I'm trying to make the transition from structs and c to classes and c++. Heres what I'm trying to do: A have a "Checkers" class and a "Board" class. Now with structs, I could just create an array of Checkers in my "board.cpp" file by doing: Checker checkers[2][12] (0 and 1 for ...

No matching function error in Xcode 3

I am trying to compile a custom class in Xcode 3 and I keep getting a no matching function call error although the same custom class compiles fine under Windows. Obviously something is not right regarding the use of curly brackets and the XCode compiler. The compiler is choking at the first curly bracket { below: : ADataBrowser(inOwne...

Creating an array from a constructor in C#

So I've been trying to figure out how to populate an array with an object I have created in C#. I found this code sample which explains a bit about what I need to do. for (int i = 0;i<empArray.Length;i++) { empArray[i] = new Employee(i+5); } But what happens if I pass more than one parameter into my construc...

Why must "stride" in the System.Drawing.Bitmap constructor be a multiple of 4?

I am writing an application that requires me to take a proprietary bitmap format (an MVTec Halcon HImage) and convert it into a System.Drawing.Bitmap in C#. The only proprietary functions given to me to help me do this involve me writing to file, except for the use of a "get pointer" function. This function is great, it gives me a poin...

C# - Deserialize a class with an internal constructor

I am working on a drag and drop system for my WPF App. The way it works is: I take the dragged Item Serialize it to xml When it gets dropped I deserialize it again. This worked fine in my test app. However, now that I am trying to do it in my real app, I have hit a snag. The class I am trying to deserialize (Microsoft.TeamFou...

PHP: How to chain method on a newly created object?

I would like to know whether there's a way to chain methods on a newly created object in PHP? Something like: class Foo { public function xyz() { ... return $this; } } $my_foo = new Foo()->xyz(); Anyone know of a way to achieve this? ...

Explicitly passing a const object to an constructor which takes const reference to a polymorphic class

I got into a problem with my classes, passing a const object (polymorphic structure) to an explicit constructor which takes a const reference to the base class of that polymorphic structure. Here is the sample (this is not from my code, it is for explanation here) class Base { ... } class Derived:public Base { ... } class Problem { ...

incompatible types in assignment of char?

Hi, I am getting an error with this code. 'Incompatible types in assignment of char to char[13]' I can't figure out how to initialize these arrays and make this work. Basically, the program takes ISBN codes (4 groups of integers and makes one string with '-' in them between each group of numbers) and verifies that they are correct. The p...

Is it good practice to put exception handling in a constructor?

Is it legitimate to have exception handling code in a class constructor, or should it be avoided? Should one avoid having exception-generating code in a constructor? ...

Question about VB.NET constructors

I'm doing a lab for school, and I came across something I have never done before: create a default constructor within my class. It involves creating a private field to store the connection string, then create a default constructor that sets the connection string. Here is what I have so far: Public Class Appointments Private sqlcon...

When to use getInstanceOf instead of constructor

Back couple of months ago I attended a presentation hosted by two representative of an independent software development company. It was mainly about good software design and practices. The two guys were talking mainly about Java and I remember them saying, that in some circumstances it is very good practice to use getInstanceOf() instea...

C++: Why does VS2005 interpret direct-initialization of local instance as a function, when the class constructor has a polymorphic parameter?

Hi there, I have the following C++ code in Visual Studio 2005... class Base {}; class Derived : public Base {}; class Other { public: Other(const Base& obj) {} void test() {} }; int _tmain(int argc, _TCHAR* argv[]) { Other other(Derived()); other.test(); return 0; } ... Compilation fails and gives: test.cpp(19) : error C2228:...

C++ Ramifications of ignoring exception from constructor

I've searched SO for an answer to this, but haven't found one. When an object throws an exception at the end of the constructor, is the object valid or is this one of those 'depends on the construction technique'? Example: struct Fraction { int m_numerator; int m_denominator; Fraction (double value, ...

ActionScript 3 constructor scope question

Hi everyone, out of curiosity I decided to experiment with the following in a Flex 4 project: public class MyGroup extends Group { public function MyGroup() { super(); var myLabel:Label = new Label(); myLabel.id = "myLabel"; myLabel.text = "My label!"; this.addElement(myLabel); ...

What's the difference between an abstract class, and a class with only protected constructors? (.NET)

What are all the difference between an abstract class, and a class with only protected constructor(s)? They seem to be pretty similar to me, in that you can't instantiate either one. EDIT: How would you create an instance in a derived class, with a base class with a protected constructor? For instance: public class ProtectedConstr...