+ 3

Constructor and Destructor

Is it possible for a constructor and destructor to call each other in C++? any example?

27th Feb 2021, 12:35 PM
Indrayudh Mandal
Indrayudh Mandal - avatar
2 ответов
+ 5
Technically no. In C++, both the constructor and destructor are programmer defined to manage the life cycle of an object. For a destructor to be called, an object of the class must have been instantiated.
27th Feb 2021, 12:45 PM
CouldntBeBothered.py
CouldntBeBothered.py - avatar
+ 1
if you call destructor inside of constructor, what would you return from it? if you call constructor from destructor, how would you free up memory? I mean: you destroy an instance while you create (ar least) another one ^^
27th Feb 2021, 3:23 PM
visph
visph - avatar