destructor Questions
1
Solved
Having class X, the following object initialization:
new (ptr) X(X());
requires an accessible destructor even since C++17. Why is that, when the object is initialized by the default constructor di...
Serenata asked 15/7 at 13:9
3
Solved
In this answer to this question, it was noted that:
If you're going to 'clear' the pointer in the dtor, a different idiom would be better - set the pointer to a known bad pointer value.
and also ...
Macneil asked 24/6 at 19:23
2
Solved
TL;DR: see compilers disagree on code by Godbolt link: https://godbolt.org/z/f7G6PTEsh
Should std::variant be nothrow destructible when its alternative has potentially throwing destructor? Clang an...
Discipline asked 10/6 at 13:56
1
Here is some logic:
A::~A() {
b.foo(this)
}
void B::foo(A*) {
.. try to get lock ..
.. remove the A object from some state ...
}
void B::bar() {
... try to get lock ...
... do some work on t...
Diecious asked 2/6 at 18:10
7
I have a Thread class like bellow
class Thread {
public:
Thread();
~Thread();
void start();
void stop();
}
So i need to call destructor from stop() method, is it a good way to do that?
Edington asked 27/11, 2013 at 7:45
25
Solved
Is there a destructor for Java? I don't seem to be able to find any documentation on this. If there isn't, how can I achieve the same effect?
To make my question more specific, I am writing an app...
Lyonnaise asked 5/10, 2008 at 13:12
8
Solved
I have a simple C++ code, but I don't know how to use the destructor:
class date {
public:
int day;
date(int m)
{
day =m;
}
~date(){
cout << "I wish you have entered the year \n" &l...
Yetac asked 27/10, 2010 at 18:22
3
In Java we can do something like override finalize(), in C++ we can do something like ~Someclass(),
But How can I do it in dart, I read the doc in https://www.dartlang.org/ but did not find answer...
Drag asked 27/7, 2015 at 5:49
3
Solved
I have a class with a vector member variable whose T is declared, but not defined. This can be a problem if no destructor for the class is defined, since the compiler might pick some other translat...
Willodeanwilloughby asked 19/8, 2023 at 2:3
3
class MainGUI(Tkinter.Tk):
# some overrides
# MAIN
gui = MainGUI(None)
gui.mainloop()
But I need to do some cleanup when the window is closed by the user. Which method in Tkinter.Tk can I ove...
Prurigo asked 2/6, 2010 at 1:13
8
Solved
golang support 'Defer Call' and when c++, I use this trick(?).
struct DeferCall
{
DeferCall() {}
~DeferCall() { doSomeThing(); }
}
void SomeMethod()
{
DeferCall deferCall;
...
}
how can I ...
Amity asked 19/11, 2016 at 7:49
5
Solved
I am trying to write the destructor for my Binary Search Tree and I know how to recursively loop through the tree, but I do not know how to do that in the destructor so that every node is deleted.
...
Dasilva asked 9/12, 2015 at 3:17
3
I have a C++ class A like this:
// third-party classes / methods, unable to change
class C {};
class B {
public:
C* getC();
};
B* legacyAPIToGetB(const char*);
// the target class
class A {
publi...
Mew asked 11/7, 2023 at 7:58
8
Solved
When would I implement IDispose on a class as opposed to a destructor? I read this article, but I'm still missing the point.
My assumption is that if I implement IDispose on an object, I can expl...
Diffractometer asked 3/12, 2008 at 23:4
2
Solved
I have following situation: In a header "test.hpp" I define:
class ObjectA {
public:
ObjectA();
~ObjectA();
static ObjectA & get_A();
};
class ObjectB {
public:
~ObjectB();
sta...
Marva asked 21/8, 2018 at 17:40
2
Solved
This symbol seems to be a compiler generated destructor. What is the difference between this one, 'compiler generated destructor' and 'scalar deleting destructor'? Are there any other types of comp...
Bainite asked 26/6, 2012 at 8:54
8
Solved
I have an object with some pointers inside of it. The destructor calls delete on these pointers. But sometimes I want to delete them, and sometimes I don't. So I'd like to be able to delete the obj...
Gallicanism asked 14/2, 2013 at 18:2
18
Solved
Most people say never throw an exception out of a destructor - doing so results in undefined behavior. Stroustrup makes the point that "the vector destructor explicitly invokes the destructor for e...
Ageless asked 24/9, 2008 at 21:34
1
Solved
I have a program that behaves differently in GCC and Clang. After simplification the minimal reproducible example is
struct A {
int i;
};
struct Finisher {
A & a;
~Finisher() { a.i = 1; }
}...
Tocsin asked 2/6, 2023 at 18:26
4
Solved
The article Are destructors overloadable? talks about overloading the destructor.
This raised a question: Can a destructor have parameters?
I've never used or seen a destructor with parameters. I...
Brandy asked 5/6, 2011 at 19:26
1
Solved
Many answers on this site mentions that delete() calls destructor. But the sample code below seems to call delete() inside the destructor. What is the correct usage of delete() when object is initi...
Cartage asked 2/5, 2023 at 10:6
2
Solved
Inventing a discriminated union/tagged variant I conclude that there is particular need in such a feature as "make destructor trivial on some conditions at compile time". I mean some kind of SFINAE...
Midgut asked 17/6, 2015 at 5:9
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
3
Solved
This is my first time posting to stackoverflow, but these threads have helped me tremendously!
Anyhow, onto my question... Are there any instances when the destructor in PHP is NOT called? The reas...
Suttle asked 8/8, 2010 at 12:22
4
Solved
Since I've dealt in the past with JavaScript’s funky "object model", I assume there is no such thing as a destructor. My searches were mildly unsuccessful, so you guys are my last hope. H...
Managing asked 21/3, 2014 at 18:5
1 Next >
© 2022 - 2024 — McMap. All rights reserved.