Top "Constructor" questions

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

Using C++ base class constructors?

While working with templates I ran into a need to make a base class constructors accessible from inherited classes for …

c++ inheritance constructor c++11
Calling virtual functions inside constructors

Suppose I have two C++ classes: class A { public: A() { fn(); } virtual void fn() { _n = 1; } int getn() { return _n; } protected: …

c++ constructor overriding virtual-functions
Static class initializer in PHP

I have an helper class with some static functions. All the functions in the class require a ‘heavy’ initialization function …

php class static constructor initializer
C# Error: Parent does not contain a constructor that takes 0 arguments

My code is public class Parent { public Parent(int i) { Console.WriteLine("parent"); } } public class Child : Parent { public Child(int …

c# inheritance constructor compiler-errors
Why do abstract classes in Java have constructors?

Why does an abstract class in Java have a constructor? What is it constructing, as we can't instantiate an abstract …

java constructor abstract-class
Should I instantiate instance variables on declaration or in the constructor?

Is there any advantage for either approach? Example 1: class A { B b = new B(); } Example 2: class A { B b; A() { …

java constructor instance-variables
How to write a simple class in C++?

I have been reading a lot of tutorials on C++ class but they miss something that other tutorials include. Can …

c++ constructor destructor public private-members
Using C# reflection to call a constructor

I have the following scenario: class Addition{ public Addition(int a){ a=5; } public static int add(int a,int b) {…

c# reflection constructor
Default member values best practice

Is it good practice when writing C++11 code to set default values for class members in the header file of …

c++ constructor c++11 header-files default-value
Why can't constructors be final, static, or abstract?

Why can't constructors be final, static, or abstract in Java? For instance, can you explain to me why this is …

java syntax constructor