destructor

Are signals in Qt automatically disconnected when one of the class is deleted

有些话、适合烂在心里 提交于 2019-11-27 17:06:24
问题 Does Qt automatically remove connections between objects , when one of the side is deleted ? e.g connect (A .. , B ..) , when A (a pointer) is deleted , or B is deleted , will the connection be disconnected ? Is it necessary to use disconnect explicitly in destructor ? 回答1: Yes, the QObject::~QObject destructor takes care of that: All signals to and from the object are automatically disconnected, and any pending posted events for the object are removed from the event queue. However, it is

GC.Collect() not collecting immediately?

你。 提交于 2019-11-27 16:15:16
In the course of a discussion in chat, I wrote this console application. Code: using System; class Program { static void Main(string[] args) { CreateClass(); Console.Write("Collecting... "); GC.Collect(); Console.WriteLine("Done"); } static void CreateClass() { SomeClass c = new SomeClass(); } } class SomeClass { ~SomeClass() { throw new Exception(); } } Result: Collecting... Done Unhandled Exception: System.Exception: Exception of type 'System.Exception' was thrown. at SomeClass.Finalize() I would have expected the app to crash before Done was printed. I don't care much about how to make it.

What determines when a class object is destroyed in PHP?

我是研究僧i 提交于 2019-11-27 15:59:05
问题 Let's say that we have class CFoo . In the following example when is CFoo::__destruct() called? function MyPHPFunc() { $foo = new CFoo(); . . . // When/where/how does $foo get destroyed/deleted? } In this example would the destructor be called when the script exits the scope of MyPHPFunc because $foo would no longer be accessible? 回答1: In PHP all values are saved in so called zval s. Those zval s contain the actual data, type information and - this is important for your question - a reference

Destructor being called twice when being explicitly invoked

倖福魔咒の 提交于 2019-11-27 14:37:40
I was experimenting with destructors in C++ with this piece of code: #include <iostream> struct temp { ~temp() { std::cout << "Hello!" << std::endl; } }; int main() { temp t; t.~temp(); } I see that "Hello!" is being printed twice. Shouldn't the calling of the destructor free the object and the destructor shouldn't be called again when it goes out of scope? Or is there some other concept? (I do not intend to do this in practice. I'm just trying to understand what's going on here.) It happens because you told it to happen. The destructor for an automatic variable is always called when the

Does std::vector call the destructor of pointers to objects? [duplicate]

这一生的挚爱 提交于 2019-11-27 14:31:41
问题 Possible Duplicate: Deleting pointers in a vector I know when an std::vector is destructed, it will call the destructor of each of its items. Does it call the destructor of pointers to objects? vector<myclass*> stuff; When stuff is destroyed, do the individual objects pointed to by the pointers inside stuff get destructed? 回答1: No. How is std::vector supposed to know how to destroy the pointed-to object? Should it use delete ? delete[] ? free ? Some other function? How is it supposed to know

explicit call to destructor is not destroying my object why?

為{幸葍}努か 提交于 2019-11-27 14:30:58
I'm calling the destructor to deallocate memory but it is not deleting my object. What is the reason behind it? my code is like this: class A { public: int a; A() { cout << "a" << endl; } }; class B :public A { public: int b; B() { cout << "b" << endl; a = 10; b = 20; } ~B() { cout << a << b << endl; } }; and I am using it like: int main() { { B b; b.~B(); b.b=100; // why this step is executed? } int x; cin>>x; return 0; } i m calling destructor to deallocate memory Why? At language level destructor does not deallocate memory occupied by the object itself. A non-trivial destructor ends object

“delete this” in constructor

折月煮酒 提交于 2019-11-27 14:27:52
问题 What actually happen when I execute this code? class MyClass { MyClass() { //do something delete this; } } 回答1: It turns out that in this particular case the code is legal, but you're ε-away from undefined behavior. The C++ standard defines the notion of the "lifetime" of an object to be the time between which its constructor has finished running and when the destructor starts running. It also explicitly states (in §3.8/5) that Before the lifetime of an object has started [...] If the object

Are destructors run when calling exit()? [duplicate]

前提是你 提交于 2019-11-27 14:25:42
问题 Possible Duplicate: Will exit() or an exception prevent an end-of-scope destructor from being called? In C++, when the application calls exit(3) are the destructors on the stack supposed to be run to unwind the stack? 回答1: No, most destructors are not run on exit() . C++98 §18.3/8 discusses this. Essentially, when exit is called static objects are destroyed, atexit handlers are executed, open C streams are flushed and closed, and files created by tmpfile are removed. Local automatic objects

Lifetime of object is over before destructor is called?

橙三吉。 提交于 2019-11-27 14:25:35
I don't understand this: 3.8/1 "The lifetime of an object of type T ends when: — if T is a class type with a non-trivial destructor (12.4), the destructor call starts , or — the storage which the object occupies is reused or released." If the lifetime ends before the destructor starts, doesn't that mean accessing members in the destructor is undefined behavior? I saw this quote too: 12.7 "For an object with a non-trivial destructor, referring to any non-static member or base class of the object after the destructor finishes execution results in undefined behavior." But it doesn't make clear

What order are destructors called and member variables destroyed in C++ using inhertitance?

删除回忆录丶 提交于 2019-11-27 14:16:33
问题 Very similar question as these, except not exactly: What is the order in which the destructors and the constructors are called in C++ Order of member constructor and destructor calls I want to know: are the member variables of the derived class destroyed before or after the destructor of the base class is called? This is in C++ using Visual Studio 2008. Thanks. 回答1: constructor: first base, then derived destruction: ~derived ~member derived ~base ~member base code: class member { string s;