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

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.

Thanks.

Best Solution

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

class A {
public:
    // Constructor
    A() { /* constructor code*/ }
};

This is how to allocate memory and construct the object:

A *a = new A();