C++ program to demonstrate the use of constructors and destructors
codeaft.cpp
#include <iostream>
using namespace std;
class codeaft
{
public:
    codeaft()
    {
        cout<<"\nConstructor is called";
    }
    ~codeaft()
    {
        cout<<"\nDestructor is called";
    }
};
int main()
{
    codeaft c;
    codeaft();
    c.~codeaft();
}
Output
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out Constructor is called Constructor is called Destructor is called Destructor is called Destructor is called codeaft@codeaft:~$
Comments and Reactions