destructor

__do_global_dtors_aux and __do_global_ctors_aux

你说的曾经没有我的故事 提交于 2020-01-29 04:54:24
问题 I disassembled a simple program written in C++ and there are these two function names. I guess that ctor means constructor and dtor means destructor, and word global maybe means that they create and destroy global objects. I cannot guess the name aux. What do these two functions do? 回答1: The addresses of constructors and destructors of static objects are each stored in a different section in ELF executable . for the constructors there is a section called .CTORS and for the destructors there

How to delete object constructed via placement new operator?

▼魔方 西西 提交于 2020-01-27 15:56:02
问题 char * buf = new char[sizeof(T)]; new (buf) T; T * t = (T *)buf; //code... //here I should destruct *t but as it is argument of template and can be //instantiated via basic types as well (say int) so such code /*t->~T();*/ //is incorrect (maybe correct? Strange, but it works on VS 2005 for basic types.) //and this code /*delete t;*/ //crashes the program. delete [] buf; So what is correct way to destruct t ? P.S. The code above is only for describing my problem, and have not real relationship

How to delete object constructed via placement new operator?

陌路散爱 提交于 2020-01-27 15:54:29
问题 char * buf = new char[sizeof(T)]; new (buf) T; T * t = (T *)buf; //code... //here I should destruct *t but as it is argument of template and can be //instantiated via basic types as well (say int) so such code /*t->~T();*/ //is incorrect (maybe correct? Strange, but it works on VS 2005 for basic types.) //and this code /*delete t;*/ //crashes the program. delete [] buf; So what is correct way to destruct t ? P.S. The code above is only for describing my problem, and have not real relationship

How to delete object constructed via placement new operator?

空扰寡人 提交于 2020-01-27 15:54:04
问题 char * buf = new char[sizeof(T)]; new (buf) T; T * t = (T *)buf; //code... //here I should destruct *t but as it is argument of template and can be //instantiated via basic types as well (say int) so such code /*t->~T();*/ //is incorrect (maybe correct? Strange, but it works on VS 2005 for basic types.) //and this code /*delete t;*/ //crashes the program. delete [] buf; So what is correct way to destruct t ? P.S. The code above is only for describing my problem, and have not real relationship

C++ destructor memory leak

Deadly 提交于 2020-01-24 13:05:05
问题 Relatively simple question about handling destructors properly... First I've got a class that's something like this: class Foo { public: ReleaseObjects() { for (std::map<size_t, Object*>::iterator iter = objects.begin(); iter != objects.end(); iter++) { delete (*iter).second; } objects.clear(); } private: std::map<size_t,Object*> objects; } So the function simply deletes the objects, which were created using 'new'. Problem is an Object class: class Bar : public Object { public: Bar() { baz =

How to handle destructors in DLL exported interfaces

≯℡__Kan透↙ 提交于 2020-01-23 12:29:09
问题 I'm trying to export a class from a DLL. I read this article on doing so: http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL The "mature" approach suggest, that an abstract class is used, so I have: // Header class IFoo{ public: virtual int getBar() = 0; } class Foo: public IFoo {...} DLLEXPORT IFoo* Create(); DLLEXPRT void Free(IFoo* inst); //DLL cpp IFoo* Create(){ return new Foo; } void Free(IFoo* inst){ delete inst; } What puzzles me: If I don't have a virtual

Error: Do not override object.Finalize. Instead, provide a destructor

一笑奈何 提交于 2020-01-21 16:13:31
问题 Getting the above error in following code. How to rectify it. Thanks. Please look for protected override void Finalize() { Dispose(false); } in the below code. using Microsoft.Win32; using System.Runtime.InteropServices; public class Kiosk : IDisposable { #region "IDisposable" // Implementing IDisposable since it might be possible for // someone to forget to cause the unhook to occur. I didn't really // see any problems with this in testing, but since the SDK says // you should do it, then

Error: Do not override object.Finalize. Instead, provide a destructor

懵懂的女人 提交于 2020-01-21 16:13:09
问题 Getting the above error in following code. How to rectify it. Thanks. Please look for protected override void Finalize() { Dispose(false); } in the below code. using Microsoft.Win32; using System.Runtime.InteropServices; public class Kiosk : IDisposable { #region "IDisposable" // Implementing IDisposable since it might be possible for // someone to forget to cause the unhook to occur. I didn't really // see any problems with this in testing, but since the SDK says // you should do it, then

Destructor in virtual inheritance

谁都会走 提交于 2020-01-20 08:41:27
问题 class Base{}; class D1:virtual public Base{}; class D2:virtual public Base{}; class DD:public D1,public D2{}; int main(){ Base *pBase=new DD; delete pBase; } This leads to crash, but I modify as below: class Base{ public: virtual ~Base(){}; }; class D1:virtual public Base{ public: virtual ~D1(){} }; class D2:virtual public Base{ public: virtual ~D2(){} }; class DD:public D1,public D2{ }; Then, it passes, but the default destructor should be the virtual dummy function, isn't it? 回答1: From the

Delete calling destructor but not deleting object?

ε祈祈猫儿з 提交于 2020-01-20 05:30:45
问题 So I have been working with c++ and pointers for a year and a half now, and i thought i had them succeed. I have called delete on objects many times before and the objects actually got deleted, or at least i thought they did. The code below is just confusing the hell out of me: #include <iostream> class MyClass { public: int a; MyClass() : a(10) { std::cout << "constructor ran\n"; } void method(std::string input_) { std::cout << param_ << "\n"; } ~MyClass() { std::cout << "destructor ran\n";