destructor

“warning: __host__ annotation on a defaulted function is ignored” <- why?

北战南征 提交于 2020-01-01 11:37:10
问题 Switching from CUDA 8.0 to CUDA 9.0 RC, I get a warning about: __host__ __device__ ~Foo() = default; The warning is: path/to/Foo.cuh(69): warning: __host__ annotation on a defaulted function("~Foo") is ignored which I didn't use to get before. Should I really be getting this warning? What's wrong with indicating you want the default destructor on both the device and the host side? 回答1: What's wrong with indicating you want the default destructor on both the device and the host side? But that

How to simulate an OnDestroy event on a TFrame in Delphi?

两盒软妹~` 提交于 2019-12-31 17:55:50
问题 How can i simulate an OnDestroy event for a TFrame in Delphi? i nievely added a constructor and destructor to my frame, thinking that is what TForm does: TframeEditCustomer = class(TFrame) ... public constructor Create(AOwner: TComponent); override; destructor Destroy; override; ... end; constructor TframeEditCustomer.Create(AOwner: TComponent) begin inherited Create(AOwner); //allocate stuff end; destructor TframeEditCustomer.Destroy; begin //cleanup stuff inherited Destroy; end; The problem

Why does Java not have any destructor like C++? [closed]

别说谁变了你拦得住时间么 提交于 2019-12-31 10:03:29
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . Java has its own garbage collection implementation so it does not require any destructor like C++ . This makes Java developer lazy in implementing memory management. Still we can have destructor along with garbage collector where developer can free resources and which can save

Can a destructor be recursive?

橙三吉。 提交于 2019-12-31 08:54:16
问题 Is this program well-defined, and if not, why exactly? #include <iostream> #include <new> struct X { int cnt; X (int i) : cnt(i) {} ~X() { std::cout << "destructor called, cnt=" << cnt << std::endl; if ( cnt-- > 0 ) this->X::~X(); // explicit recursive call to dtor } }; int main() { char* buf = new char[sizeof(X)]; X* p = new(buf) X(7); p->X::~X(); // explicit call to dtor delete[] buf; } My reasoning: although invoking a destructor twice is undefined behavior, per 12.4/14, what it says

Can a destructor be recursive?

旧时模样 提交于 2019-12-31 08:53:47
问题 Is this program well-defined, and if not, why exactly? #include <iostream> #include <new> struct X { int cnt; X (int i) : cnt(i) {} ~X() { std::cout << "destructor called, cnt=" << cnt << std::endl; if ( cnt-- > 0 ) this->X::~X(); // explicit recursive call to dtor } }; int main() { char* buf = new char[sizeof(X)]; X* p = new(buf) X(7); p->X::~X(); // explicit call to dtor delete[] buf; } My reasoning: although invoking a destructor twice is undefined behavior, per 12.4/14, what it says

C++ circular reference problem

纵饮孤独 提交于 2019-12-31 06:53:21
问题 I have 2 classes: DataObject and DataElement . DataObject holds pointers to (only) DataElement s, and a DataElement contains pointers to several types, among which a DataObject . This used to be no problem, since I only use pointers to DataObject s in DataElement , so a forward declaration of DataObject in the header of DataElement is enough. Now, however, I try to add a destructor to DataElement , in which I need a delete on a DataObject . On this the compiler says: dataelement/destructor.cc

Destructor class in TObject and NIL Delphi

烈酒焚心 提交于 2019-12-31 05:36:07
问题 I am wondering why after I invoke Free method the object is not nil . What I mean for example next class: type Ta = class(TObject) public i: integer; destructor Destroy; override; end; destructor Ta.Destroy; begin inherited; end; procedure Form1.Button1; var a: Ta; begin a := Ta.Create; a.Free; if a = nil then button1.Caption := 'is assigned' else button1.caption := 'is not assigned'; end; My question is why after freeing the object is not nil and how will I make a to be nil after destructor

Why does the destructor run twice in C++?

天大地大妈咪最大 提交于 2019-12-31 00:57:30
问题 While doing my programming assignments, I seem to be stumbling over basic C++ concepts. I found the bug in my program and it was caused by my destructor running more times than I expected. Here is a code sample demonstrating what I am doing wrong, down to the bare essentials. #include <iostream> using namespace std; class A { public: A(int num) { number = num; cout << "A constructed with number " << number << ".\n"; } ~A() { cout << "A destructed with number " << number << ".\n"; } private:

C++ Strange constructor behaviour

你。 提交于 2019-12-30 21:38:10
问题 Can anybody explain to me the difference between Complex a; and Complex b(); ? #include<iostream> class Complex { public: Complex() { std::cout << "Complex Constructor 1" << std::endl; } Complex(float re, float im) { std::cout << "Complex Constructor 2" << std::endl; } ~Complex() { std::cout << "Complex Destructor" << std::endl; } }; int main() { Complex a; std::cout << "--------------------------" << std::endl; Complex b(); std::cout << "--------------------------" << std::endl; Complex c(0

C++ Strange constructor behaviour

我的未来我决定 提交于 2019-12-30 21:38:07
问题 Can anybody explain to me the difference between Complex a; and Complex b(); ? #include<iostream> class Complex { public: Complex() { std::cout << "Complex Constructor 1" << std::endl; } Complex(float re, float im) { std::cout << "Complex Constructor 2" << std::endl; } ~Complex() { std::cout << "Complex Destructor" << std::endl; } }; int main() { Complex a; std::cout << "--------------------------" << std::endl; Complex b(); std::cout << "--------------------------" << std::endl; Complex c(0