vector::push_back struct without destructor being called?

Is it possible to push a struct into a vector without the original object being destroyed and the copy constructor called (other than wrapping the vector in another class)?
Why would pushing something into a vector destroy the original object?

Post your code that illustrates the problem.

it's created inline like so:

logs.push_back(logobj(MKXCODE(0), "", data, sizeof(WORD)+sizeof(DWORD64)+(endat-startat), true));

The issue is that there is a static class variable that keeps track of pointers to dynamically allocated memory.
When an object is destroyed, the pointer is removed from this vector. If no other pointers to the same memory exist in the vector, it is deallocated.

I could write my own copy constructor to add the pointer there as well, but I'd have to assign every member variable manually, remember to go back and change it if I add any new members to the class, etc.

It's a little tedious. I was wondering if there's an easier way
Last edited on
So you're talking about a temporary object, not a "normal" object.

Have you tried using initialization syntax instead?
logs.push_back({MKXCODE(0), "", data, sizeof(WORD)+sizeof(DWORD64)+(endat-startat), true});
I would, but can't use C++11 unfortunately
Okay, then what is the problem? If you can't use modern C++ then you're probably stuck with the behavior you have.
Topic archived. No new replies allowed.