Why is dtor called before the end of the range when I call ctor from main? (Experimental)

Here I call the constructor of the class ain main()without creating an object of this class, and it looks like the destructor is called right after the call. What is really going on here? In my understanding, is this because I did not create an object with some memory? What is called dtor here? How is this implemented? Share your thoughts on this.

#include<iostream>
using namespace std;

class a{
    public:
        a(){
            cout<<"\nctor";
        }
        ~a(){
            cout<<"\ndtor";
        }
};

int main(){
a(); //why the dtor is getting called before the scope ends?
cout<<"\nctor_called\n";
}

o / p programs:

ctor
dtor
ctor_called
+4
source share
1 answer

You do not call the constructor (you cannot directly). You create a temporary object that is immediately destroyed.

Try

a anA;
+6
source

Source: https://habr.com/ru/post/1534505/