c++,destructor,new-operator,placement-new
Why can I call the destructor? Because it is a public member function, and you can call public member functions. Why is the object not deleted? In your specific case, it still exists because A has a trivial destructor. If it had a non-trivial one, it would be deleted...
You are mixing the following notions in such a way that it makes me think that you are unclear on what they are supposed to be: Base classs/derived class destructors. Placement new operator. Memory allocation and deallcation. When you use the plain old operator new to allocate objects, two things...
c++,new-operator,language-lawyer,placement-new
Generally, working with placement new in this way is not a good idea. Calling an initializer from the first new, or calling an initializer instead of placement new are both considered to be better form than the code you've provided. However, in this case, the behaviour of calling placement new...
c++,raii,placement-new,explicit-destructor-call
Your solution seems overly complex. I would code it like this: class ResourceManager { ResourceManager() {} ResourceManager(A* a_ptr) : b_ptr(new B(a)), c_ptr(new C(b_ptr.get())) {} ResourceManager& operator=(ResourceManager&& that) { // the order of these moves/assignments is important // The old value of *(this->c_ptr) will be destroyed before // the old value...
This is calling placement new which places an object into the location specified in parenthesis. With generalized unions accommodating class types I'd expect placement new to be more widely used: to change the tag to a class type you'll need to construct the object, probably using placement new (obviously, after...
c++,language-lawyer,placement-new
what happens to the original type? You mean the original object? It get's destroyed, that is, its lifetime ends. The lifetime of the array object of type buffer_type [1000] ends as soon as you reuse its storage. A program may end the lifetime of any object by reusing the...
You can look at a class that manages resources like wrapA and you need to basically ask two questions: Does it correctly manage its resources: correct construction, assignment, destruction. Do any of its public data or functions potentially allow for easy corruption of the resource management scheme? Let's start with...
c++,memory,segmentation-fault,placement-new
Reading a variable which has not been initialized is undefined behavior. It is not unreasonable then that your compiler sets the pointer's value to NULL before assignment, which would cause a short-circuit on the if statement in your copy constructor and thus *a would never be executed.