Questions tagged [constructor]

A special type of subroutine called at the creation of an object.

Filter by
Sorted by
Tagged with
39
votes
5answers
9k views

Database connection in constructor and destructor

I am playing with different ways to do database interaction in PHP, and one of the ideas I have been playing with is connecting to the DB in the constructor and disconnecting in the destructor. This ...
12
votes
3answers
4k views

Parameterised Constructors

Finally, Parameterised Constructors are possible in VBA. Background: One rainy day, I came up with an idea: take a static class and expose one property as default (like it was done in the Reverse ...
8
votes
1answer
542 views

Creating Inheritance hierarchy using function constructor

Problem statement You need to create the Animal base class having four fields: a. name b. ...
8
votes
4answers
16k views

Kelvin-Fahrenheit-Celsius temperature converter

I am curious if it would ever be in good practice to omit constructor definitions from a class. Here, the intention of the Temperature class is to simply convert between one temperature scale to ...
2
votes
3answers
1k views

Review of three constructors for a String class

I have the following declaration in my String.h file: private: char* nstring; int nlength; }; The following are three constructors I've implemented in ...