explicit-destructor-call Questions
4
I stumbled upon the following code snippet:
#include <iostream>
#include <string>
using namespace std;
class First
{
string *s;
public:
First() { s = new string("Text");}
~First() ...
Hayashi asked 12/11, 2018 at 12:31
2
Solved
In The C++ programming language Edition 4 there is an example of a vector implementation, see relevant code at the end of the message.
uninitialized_move() initializes new T objects into the new m...
Soften asked 14/12, 2013 at 22:34
1
Solved
For ordinary objects (even for const ones), it is permissible to end their lifetime by explicitly calling the destructor. Later, for example, the program can start another object lifetime in the sa...
Levitan asked 23/8, 2021 at 5:15
1
Solved
is it required by the standard to call non-trivial destructor when you know that in this specific case the destructor is a noop ?
is the code likely to be broken by compliers if the destructor is ...
Conveyancer asked 12/6, 2019 at 10:3
2
Solved
In my constructor, I have to destroy any remaining resources if any code in it throws. I'd like to avoid writing duplicate code so I just call the destructor in the catch block which than frees any...
Lissy asked 18/2, 2019 at 23:20
3
Solved
I have class Data which can hold a pointer to an object. I want to be able to call its destructor manually later on, for which I need its address stored in a variable but it seems that taking the a...
Helicline asked 10/10, 2018 at 9:54
3
Solved
In the following C++ code, I am allowed to explicitly call the destructor but not the constructor. Why is that? Wouldn't be explicit ctor call more expressive and unified with the dtor case?
class...
Legionnaire asked 17/7, 2017 at 10:40
2
Solved
I know that calling destructor explicitly can lead to undefined behavior because of double destructor calling, like here:
#include <vector>
int main() {
std::vector<int> foo(10);
fo...
Baler asked 4/3, 2017 at 17:19
1
I just wrote following program & it compiles & runs fine. (see live demo here.)
#include <iostream>
typedef int T;
int main()
{
int a=3;
std::cout<<a<<'\n';
a.~T...
Axum asked 26/8, 2015 at 3:25
3
I have this code:
struct data {
void doNothing() {}
};
int main() {
data* ptr = new data();
ptr->~data();
ptr->doNothing();
::operator delete(ptr);
}
Note that doNothing() is being c...
Maramarabel asked 18/5, 2015 at 18:21
1
Solved
Consider the following code:
#include <iostream>
typedef int t;
t a=42;
int main()
{
a.t::~t();
std::cout << a; //42
}
I'm expected that a will be destroyed. But it is not true, ...
Sedate asked 2/6, 2014 at 18:9
1
Solved
Current Implementation
I have a class containing unique_ptr fields which depend on one other:
class ResourceManager {
ResourceManager() {}
ResourceManager(A* a_ptr) :
b_ptr(new B(a)),
c_ptr(...
Orderly asked 29/4, 2014 at 16:32
3
Solved
In a recent interview, I was asked to answer if this code is safe and if it is when would I use something like this:
template<class T> T *CTricky<T>::Safe_Or_Not (T *object)
{
objec...
Hairston asked 12/2, 2014 at 5:48
1
Solved
I know that I can declare a destructor =delete or private in order to prevent the program from implicitly deleting the object at the end of scope. I also know that if it's private, I can have a mem...
Flaminius asked 17/9, 2013 at 1:49
2
Solved
Consider this code (for different values of renew and cleanse):
struct T {
int mem;
T() { }
~T() { mem = 42; }
};
// identity functions,
// but breaks any connexion between input and output
i...
Leannleanna asked 24/7, 2012 at 19:4
4
Solved
Here by "simple", I mean a class with non-virtual empty destructor or POD type.
Typical example:
char buffer[SIZE];
T *p = new(buffer) T;
...
p->~T(); // <---- always ?
What happens if we...
Sthilaire asked 11/5, 2012 at 6:46
1
© 2022 - 2025 — McMap. All rights reserved.