destructor

Copy Constructor Big 3 C++ issue

£可爱£侵袭症+ 提交于 2019-12-08 02:01:27
问题 I am struggling with implementing big 3 idea (assignment operator overload, copy constructor, destructor). my code below will crash the program. It compiles so I cannot even see any error hint. Please help. enter code here #include <iostream> using namespace std; #include <string> #include <fstream> #include <cmath> #include <cstdlib> #include <ctime> #include <vector> #include <windows.h> #include <cstring> #include <cctype> #include <iomanip> #include <algorithm> #include<sstream> class

php destructor called too soon with fluent interface

拈花ヽ惹草 提交于 2019-12-08 01:34:26
问题 I found a really weird thing about php destructor: basically I have a database management class which loads an adapter using a factory to define which adapter should be loaded (mysql, mysqli, etc.) I'll write down only the part of the code insteresting, as the class itself is way longer but code isn't involved in the current trouble The problem occurs ONLY with mysql (mysqli & pdo works just fine) but for compatibility purposes, getting rid of mysql it's out of question. class manager {

Fortran final routine calls itself before variable goes out of scope

白昼怎懂夜的黑 提交于 2019-12-07 22:53:57
问题 I have a problem with Fortran destructors/final routines. Having the code below: module my_type_module implicit none type my_type contains final :: destructor end type my_type interface my_type ! Constructor declaration module procedure my_type_constructor end interface my_type contains function my_type_constructor() type(my_type) :: my_type_constructor print *, 'In constructor address is: ', & loc(my_type_constructor) end function my_type_constructor subroutine destructor(this) type(my_type)

Can static allocated memory become invalid during static deinitialization?

风格不统一 提交于 2019-12-07 21:17:18
问题 Say I have defined a variable like this (C++): static const char str[] = "Here is some string data"; And I have a statically allocated class instance which references this array in its destructor, can this go wrong? E.g. could the str variable somehow get invalid? class A { ~A() { cout << str << endl; } }; static A a; My assumption is that it can't go wrong, but I can find it clearly stated anywhere. I want to know this for sure. My assumption is that we can not predict the sequence in which

How to detect C++11 under MSVC for noexcept feature?

柔情痞子 提交于 2019-12-07 10:10:37
问题 I'm working with a C++ library. The library's minimum requirements are C++03. I'm catching some warnings under Visual Studio 2015 regarding throwing destructors: ... algparam.h(271): warning C4297: 'AlgorithmParametersBase::~AlgorithmParametersBase': function assumed not to throw an exception but does ... algparam.h(271): note: destructor or deallocator has a (possibly implicit) non-throwing exception specification The throw was by design in the 1990s when the code was written, but its

failed constructor and failed destructor in C++

試著忘記壹切 提交于 2019-12-07 09:22:55
问题 I have one question about failed constructor and failed destructor in C++. I noticed that when the constructor failed, an exception will be thrown. But there is no exception thrown in destructor. My question is 1) If constructor failed, what exception will be thrown? bad_alloc? or anything else related? Under what situation, a constructor would fail? What about the successfully constructed part? 2) Under what situation, a destructor would fail? If no exception is thrown, what would happen to

Destructor called on assignment between (stack) variables?

半世苍凉 提交于 2019-12-07 08:42:51
问题 matrix m1(5,5); matrix m2(5,5); m1 = matrix(m2); For the above code (for an arbitrary class, matrix), will the destructor be called for the information associated with m1, when the information of m2 is copied over to it? 回答1: No, an assignment operator will need to deal with releasing whatever resources m1 may hold before performing an assignment. The destructor will be called only when m1 is about to go out of scope. 回答2: No, once an object which is allocated on the stack is constructed it

Sample use of a C# Destructor

时光怂恿深爱的人放手 提交于 2019-12-07 07:35:33
问题 I'm reading about destructors in C# but I'm having trouble finding a decent use-case for it. Could someone provide an example of usage with an explanation? Much, much appreciated. Update The code sample in the book implements both a Desctuctor and a Dispose() method, see this code snippet from the book. class MyClass { bool disposed = false; // Disposal status public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ~MyClass() { Dispose(false); } protected virtual void Dispose(bool

Can I call delete on primitives?

故事扮演 提交于 2019-12-07 06:22:50
问题 I have a templated class, myFoo, which stores "stuff" of type T which can be either primitive or pointers to complex types. When myFoo is deleted, I want to release all the memory associated with everything it happens to be storing. This means I need to call delete on every pointer being stored but I might also end up calling delete on a primitive. Is this safe?? I've included a sketch of myFoo below to better highlight what's going on. I'm not sure if the behaviour of the destructor is well

how to wrtie destructor for class including a Union

自古美人都是妖i 提交于 2019-12-07 06:05:47
问题 I have a class contain different type of variables like this. class Field { union DATATYPE { int intValue; double doubleValue; char* charValue; MyClass* MyClassValue; } Value; ~Field() { delete[] Value.charValue; delete Value.MyClassValue; } } This destructor gives error. Since some objects don't have charValue initialized, the attempting to delete it raised error. 来源: https://stackoverflow.com/questions/16025132/how-to-wrtie-destructor-for-class-including-a-union