ProAnswers.org

What is a constructor in c++?

1 Like

A constructor is like a `factory’: it builds objects from dust.

Constructors are like `init functions’; they build a valid object. The constructor turns a pile of incoherent arbitrary bits into a living object. Minimally it initializes any internally used fields that are needed, but it may also allocate resources (memory, files, semaphores, sockets, .).

`ctor’ is a typical abbreviation for constructor.

constructor creates an object and initializes it. It also creates vtable for virtual functions. It is different from other methods in a class.