destructor

Is sending error report from PHP Exception __destruct() method a Good or Bad Idea?

有些话、适合烂在心里 提交于 2019-12-12 09:48:27
问题 I am designing an error handling system for my application. I want to base it on exceptions, and I want to get notified by email about every exception which I had not expected. I thought of a class: class My_Exception extends Exception { private $sendErrorReport = true; public function __destruct() { if ($this->sendErrorReport) { // send the error report by email } } public function cancelErrorReport() { $this->sendErrorReport = false; } } And I want to do something like this: try { do

Undefined reference to destructor error in c++?

最后都变了- 提交于 2019-12-12 09:06:42
问题 Here is the class class Email{ private: char to[100]; char from[100]; char subject[200]; char body[1000]; public: Email(); Email(char *za,char *od,char *tema, char *telo){ strcpy(to,za); strcpy(from,od); strcpy(subject,tema); strcpy(body,telo); } ~Email(); void setTo(char *to) {strcpy(this->to,to);} void setFrom(char *from) {strcpy(this->from,from);} void setSubject(char *subject) {strcpy(this->subject,subject);} void setBody (char *body) {strcpy(this->body,body);} char* getTo () {return to;}

Delete expression

被刻印的时光 ゝ 提交于 2019-12-12 08:55:59
问题 Reference here That destructor will also implicitly call the destructor of the auto_ptr object. And that will delete the pointer it holds, that points to the C object - without knowing the definition of C! That appeared in the .cpp file where struct A's constructor is defined. This was curious and then 5.3.5/5 states - "If the object being deleted has incomplete class type at the point of deletion and the complete class has a non-trivial destructor or a deallocation function, the behavior is

Most concise way to disable copying class in C++11

最后都变了- 提交于 2019-12-12 07:30:55
问题 I have a problem dealing with deprecated since C++11 default generation of copy constructor and copy assignment operator when there is a user-defined destructor. For most sufficiently simple classes default-generated constructors, operators and destructor are fine. Consider the following reasons to declare destructor: Making trivial destructor virtual in base class: // header class Base1 { public: virtual ~Base1() = default; }; class Base2 { public: virtual ~Base2(); }; // source Base2::

Are there any unexpected consequences of calling a destructor from the assignment operator?

对着背影说爱祢 提交于 2019-12-12 06:12:38
问题 For example: class Foo : public Bar { ~Foo() { // Do some complicated stuff } Foo &operator=(const Foo &rhs) { if (&rhs != this) { ~Foo(); // Is this safe? // Do more stuff } } } Are there any unexpected consequences of calling the destructor explicitly with regard to inheritance and other such things? Is there any reason to abstract out the destructor code into a void destruct() function and call that instead? 回答1: Calling the destructor is a bad idea in the simplest case, and a horrible one

Inner class destructor is called after Base class destructor

心已入冬 提交于 2019-12-12 03:28:19
问题 i have a basic and simply question. I have this scenario: #include <iostream> using namespace std; class Inner1 { public: ~Inner1() {cout << "Inner1 Des\n";}; }; class Inner2 { public: ~Inner2() {cout << "Inner2 Des\n";}; }; class Base { public: ~Base() {cout << "Base Des\n";}; Inner1 inner1; Inner2 inner2; }; int main() { Base base; return 0; } And my console tells me now this: Base destructor called Inner2 destructor called Inner1 destructor called Is this the normal behavior? Because the

PHP __destruct is causing net::ERR_CONNECTION_RESET register_shutdown_function is not. What's the difference?

你说的曾经没有我的故事 提交于 2019-12-12 02:29:45
问题 so I have following problem. I have a session class that should save it's data to database at the end of the request execution. Basically, when it is destructed. I'm using singleton pattern in this case. I have a destructor like this: public function __destruct() { $this->_save(); // _save is public // exit('I can reach this point with no error'); } But with that code I get net::ERR_CONNECTION_RESET from chrome and other browsers. If I comment out the destructor and place this in constructor:

Why destructors are not called in reverse order for array of objects?

纵饮孤独 提交于 2019-12-12 01:52:29
问题 Destructors are called in reverse order of object creation in C++ but I do not understand why it is not maintained for array of objects. #include <iostream> using namespace std; class test { int nmbr; static int c; public: test(int j) { cout<<"constructor is called for object no :"<<j<<endl; nmbr=j; }; ~test() { c++; cout<<"destructor is called for object no :"<<c<<endl; }; }; int test::c=0; int main() { test ob[]={test(1),test(2),test(3)}; return 0; } The above program outputs constructor is

Virtual function not functioning properly [duplicate]

霸气de小男生 提交于 2019-12-12 01:49:54
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: class has virtual functions and accessible non-virtual destructor I got this code from following a tutorial by thenewboston: #include <iostream> using namespace std; class Enemy { public: virtual void attack(){}; }; class Ninja: public Enemy { public: void attack(){ cout << "ninja attack"<<endl; } }; class Monster: public Enemy { public: void attack(){ cout << "monster attack"<<endl; } }; int main() { Ninja n;

Finalizer Throws Random Exceptions, Raises Random Errors, Hangs App

孤者浪人 提交于 2019-12-12 01:34:09
问题 I have a class in C++/CLI that uses unmanaged resources (a HANDLE for a native thread (i.e. from CreateThread()) and an LPVOID for a fiber from CreateFiber/ConvertThreadToFiber). Under the advice I got from MSDN I'm cleaning up the unmanaged resources in the finalizer (!Fiber()), and the destructor (~Fiber()) is calling the finalizer. Here's the code: Fiber::~Fiber () { this->!Fiber(); } Fiber::!Fiber () { if (thread!=NULL) { delete thread; thread=NULL; } if (fiber!=NULL) { DeleteFiber(fiber)