Anonymous Object in C++

In a C++ programming an object are created with names but It is still possible to create object without name such object are known as anonymous object.

When constructor and destructor are called, the data members are initialize and destroyed respectively.

Without object we can initialize and destroy the content of the class.

All these operations are carried out without object or we can also assume that operations are carried out using an anonymous object.

Output

Note: In the above program, we have created class “A” which contains constructor and destructor.

In the main() function, no object is created.

The constructor are called directly.

Calling constructor directly means creating anonymous object. It is not possible to create more than one anonymous object at a time.                              

When constructor execution ends , destructor is executed to destroy the object.