C++ – How to define dynamic constructor in C++?


It allocates memory to the objects while creating to sane memory space.
but how to define the dynamic constructor.

plz explain with an example.


Best Solution

There is no dynamic constructor in C++. This is how to define a constructor for class A:

class A {
    // Constructor
    A() { /* constructor code*/ }

This is how to allocate memory and construct the object:

A *a = new A();