destructor

Does PHP closing tag destructs an instantiated class (object)?

<?php class Student { public $name = "Benjamin"; } $name = new Student(); ?> <p>Hello, there. My name is <?php $name->name ?></p> The above code doesn't work as intended (printing the name within "p" tags). But the below code, of course, does work: <?php class Student { public $name = "Benjamin"; } $name = new Student(); echo '<...

Smart pointers, or "better" destructor

Which type of the smart pointer (shared, scoped) would be for such a data structures the most suitable... Structure 1: //Class with cross-references to points p1, p2 class PointTopo { private: double x, y; PointTopo * p1; PointTopo * p2; public: PointTopo(double xx, double yy): x(xx), y(yy) {this-> p1 = NULL; this->p...

Use of destructor in c# ?

Hi all, I am little bit confused about use of destructor in c#. In my knowledge we can't call destructor acording to my wish it will call automatically before garbage collector for performing some work over class (object) so i want to ask if we are using destructor in c# then whe we need to garbage collector. As i know that destructor ...

Force virtual destructors? C++

I didnt see it in the C++ Faq lite How do i define a base class so every class inheriting it is required to define a destructor? I tried running this program struct VDtor { virtual ~VDtor()=0; }; struct Test:VDtor { virtual ~Test(){} }; int main() { delete new Test; return 0; } http://codepad.org/wFcE71w3 With the error In functi...

Default constructor

struct Base{ Base(Base &){} // suppress default constructor }; struct Derived : Base{ }; int main(){ Derived d; } The code shown gives error because the default constructor (implicit) of 'Base' is suppressed. Indeed the standard says in $12.1 "If there is no user-declared constructor for class X, a default constructor ...

Desctuction of object is causing the crash of the program

Here is a snippet of a considerably big C++ program: map<int, int>::iterator class_it = docsCountPerClass.begin(); for( ;class_it != docsCountPerClass.end(); class_it++) { cout << "classid: " << class_it->first << '\n'; vector<term_importance> ti; ti.reserve(termids.size()); vector<int>::iterator term_it = termids.begin...

What is the order of destruction of objects in VBScript?

In what order are objects in a .vbs destroyed? That is, given these globals: Set x = New Xxx Set y = New Yyy I'm interested in answers to any of the following. For instances of classes implemented in the .VBS, in what order will Class_Terminate be called? Cursory poking suggests in the order (not reverse order!) of creation, but is...

C++ Virtual Destructor Crash

I have the following class hierarchy: class Base { public: virtual ~Base(); }; class Derived : public Base { public: virtual ~Derived(); }; class MoreDerived : public Derived { public: virtual ~MoreDerived(); }; along with an objects Base* base = new Base(); MoreDerived* obj = new MoreDer...

Deleting objects from template list

Hi All, I have a template list say, List<SuperClass*>* mList; for(int i = 0;i < mList->ElementsCount();i++) mList->DeleteElementAtIndex(i); in mList objects of subclasses are added. while on deleting object from the list, should i need to convert the object into corresponding subclasses and call delete method ...

Constructor calling a destructor

Is it possible to have a constructor calling a destructor in C#? ...

Can static allocated memory become invalid during static deinitialization?

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 assu...

Why doesn't shared_ptr have a virtual descructor? (and how can I get around this?)

I wanted to make a special version of shared_ptr that would perform specific operations when it was created or destroyed, but my plans appear to be foiled by the realization that shared_ptr's destructor is non virtual, meaning when I override it, my pointers never get cleaned up when the last instance of them are destroyed. The only al...

Java memory leak, destroy/finalize object

Hi! I am experiencing a memory leak with a code similar to the one below (it's a simulation with different inputs at every loop). The problem The object Object_XXX is quite complex, with connections to databases and other objects populated with data from databases aswell. for(int i=0; i<MAX; i=i+1){ Class_XXX Object_XXX ...

How to break with GDB at object destruction if there is no destructor?

How to break with GDB at object destruction if there is no destructor? ...

Saving a Class to disk on dispose: Does my code have bugs?

I am attempting to make a simple class that serializes itself to disk when it is no longer in use. The code I have right now (see below). The code I have now seems to work, but I am not fully confident in my knowledge, so I am wondering if anyone else sees any significant problems with this code. void IDisposable.Dispose() { Dispo...

Delete the current object and create an array of new ones

There is a member function which I would like to delete the current object and create an array of new ones in its place. How is it possible? The following code is an attempt of mine which has a lot of mistakes. void LernaeanHydra::split(int parts) { LernaeanHydra *new_heads = new LernaeanHydra[parts]; for (int i = 0; i < parts; ...

Problematic code??? Is there a problem with my destructor?

Hi, My code compiles and run, but i've been told that it is quite problematic. I don't understand where do i go wrong. Also, isn't it suppose to be wrong to declare "char _arrName[2];" and to do the assignment "_arrName[2]= '\0';" ? Isn't is a "out of boundaries" bug? #include <iostream> using namespace std; class Base { protected: cha...

Singletons destructors

Hello, I'm using boost's singletons (boost::serialization::singleton). I have to control the queue of class destructings. One singleton consist of the object whicn uses object from second singleton. And I have to delete second singleton, before the first one. Can I do this? p.s. please, don't say anything about singleton programming tec...

default virtual d'tor

Hello everyone, let's assume I have two classe class Base{}; class Derived: public Base{}; none has d'tor, in this case if I declare about variables: Base b; Derived d; my compiler will produce for me d'tors, my question is, the default d'tors of the b and d will be virtual or not? ...

shared_ptr magic :)

Mr. Lidström and me had an argument :) Mr. Lidström's claim is that a construct shared_ptr<Base> p(new Derived); doesn't require Base to have a virtual destructor. @Daniel: Really? Will the shared_ptr clean up correctly? Could you please in this case demonstrate how that effect could be implemented? – Armen Tsirunyan @Armen: The sh...