why this code generates two destructor message, and why this happens without Constructing twice
why this code generates two destructor
i tried with std::move , same thing
the only reasonable result is when I use vector of pointers
#include
#include
#include
class Obj {
public:
static int gen_id;
int id;
Obj()
{
id = gen_id;
std::cout << "Hello from Obj: " << Obj::id << " " << this<< "\n";
gen_id++;
}
~Obj()
{
std::cout << "Mdying : " << Obj::id << " " << this << "\n" ;
}
};
int Obj::gen_id = 0;
int main()
{
std::vector v;
Obj o = Obj();
v.push_back(std::move(o));
}