Questions tagged [destruction]
70 questions
54
votes
9 answers
Destruction order of static objects in C++
Can I control the order static objects are being destructed?
Is there any way to enforce my desired order? For example to specify in some way that I would like a certain object to be destroyed last, or at least after another static object?
![](../../users/profiles/46418.webp)
Gal Goldman
- 7,995
- 11
- 42
- 45
20
votes
2 answers
How does Qt delete objects ? And what is the best way to store QObjects?
I heard that objects in Qt will automatically delete their children, I want to know what will happen in those situations.
#include
#include
#include
#include
int main(int argc, char **argv)
{
…
![](../../users/profiles/2756371.webp)
Linlix
- 347
- 1
- 2
- 9
14
votes
3 answers
Late destruction of function parameters
According to 5.2.2/4 "Function call" in n4640 (8.2.2/4 in n4659) function parameters are created and destroyed in the context of the caller. And implementations are allowed to delay the destruction of function parameters to the end of the enclosing…
![](../../users/profiles/187690.webp)
AnT
- 291,388
- 39
- 487
- 734
13
votes
3 answers
Clojure applying a map and keyword arguments destruction
Consider a function with the following signature:
(defn make-widget [& {:keys [x y] :or {x 10 y 20}}]
...)
What is the best way to pass a map to the function, e.g.:
(make-widget {:x 100})
or
(make-widget {:y 200 :x 0})
What I have currently…
![](../../users/profiles/240950.webp)
Zaur Nasibov
- 20,924
- 9
- 49
- 79
11
votes
2 answers
Would it be reasonable to define destruction order of vector elements?
I know that vector elements destruction order is not defined by C++ standard (see Order of destruction of elements of an std::vector) and I saw that all compilers I checked do this destruction from begin to end - which is quite surprising to me…
![](../../users/profiles/1463922.webp)
PiotrNycz
- 20,687
- 7
- 55
- 102
10
votes
2 answers
Does the vptr change during destruction?
I was looking at this article, and it says "Upon entry to the base class destructor, the object becomes a base class object, and all parts of C++—virtual functions, dynamic_casts, etc.—treat it that way." Does this mean that the vptr has changed…
![](../../users/profiles/189456.webp)
pythonic metaphor
- 9,476
- 16
- 59
- 103
10
votes
2 answers
Shouldn't the temporary A(3) be destroyed before "Here" is printed?
Shouldn't the temporary A(3) be destroyed before "Here" gets printed?
#include
struct A
{
int a;
A() { std::cout << "A()" << std::endl; }
A(int a) : a(a) { std::cout << "A(" << a << ")" << std::endl; }
~A() { std::cout <<…
![](../../users/profiles/4470210.webp)
François-Marie Arouet
- 647
- 4
- 9
6
votes
4 answers
Correct way to destroy a form and show another in Delphi
Currently in my program I have a Startup form, and a Main form. The startup form shows for a second or two.
Right now, I have the following code within a timer:
frmStartup.Destroy;
frmMain := TfrmMain.Create(Self);
frmMain.Show;
Right now,…
![](../../users/profiles/1207498.webp)
James
- 133
- 1
- 3
- 9
6
votes
1 answer
Spring Custom Scope Lifecycle Bean Termination
Question: How can I tell Spring that a set of beans with a custom scope should all be considered garbage, so that the next request on the same thread would not re-use their state?
What I've done: I've implemented a custom scope in Spring, to mimic…
![](../../users/profiles/1264473.webp)
Andrew Cotton
- 335
- 1
- 10
5
votes
4 answers
Local variables construction and destruction with optimizer involved
If I have this code:
class A { ... };
class B { ... };
void dummy()
{
A a(...);
B b(...);
...
}
I know that variables a and b will be destroyed in reverse allocation order (b will be destroyed first, then a); but can I be sure that the…
![](../../users/profiles/474258.webp)
Loghorn
- 2,519
- 14
- 22
5
votes
1 answer
Array destruction and unused vars marked by eslint
I have code like this in my code:
let [a, b, c, d, e] = await component.getState.call(game.gameId);
Variables b, c, e used below in code but not a and d. In the same time I have eslint check that marks unused variables.
Is there any way to write…
![](../../users/profiles/291372.webp)
Alex G.P.
- 8,092
- 5
- 37
- 75
5
votes
3 answers
Behaviour of explicit call to destructor
The definition of some_class is:
class some_class
{
// stuff
public:
~some_class()
{
delete dynamic_three;
}
private:
classA one;
classB two;
classC* dynamic_three;
}
When the lifetime of a object ends, its…
![](../../users/profiles/1794803.webp)
Peregring-lk
- 9,237
- 6
- 37
- 86
4
votes
3 answers
Automatic object destruction
Is the destruction of automatic objects (objects created on the stack) guaranteed to be executed not before they go out of scope?
To clarify:
#include
class A {
public:
A() {
std::cout << "1";
}
~A() {
std::cout…
![](../../users/profiles/430766.webp)
bitmask
- 25,740
- 12
- 80
- 142
4
votes
1 answer
Destruction order of the main thread and the use of pthread_key_create
I was wondering about the use of pthread_key_create while passing in a destructor function.
I wanted to have something like this:
static ComplexObject foo;
void workoncomplex(void *) {
foo.dosomestuff();
}
static pthread_key_t…
![](../../users/profiles/109019.webp)
Salgar
- 7,252
- 1
- 24
- 38
4
votes
1 answer
building a vector to allow uninitialized storage
Let's say I want to build a vector container that, unlike std::vector, allows uninitialized storage. The usage of the container, say vec , would be roughly like this:
User explicitly states the vector should allocate N uninitialized elements…
![](../../users/profiles/2644390.webp)
iavr
- 7,277
- 1
- 13
- 50