Is "delete" really going away?

Minas Mina minas_mina1990 at hotmail.co.uk
Sun Jul 29 06:03:09 PDT 2012


I think having the delete keyword for classes was a very good 
thing, altough I don't know the problems it has for the GC and 
probably other things.

Consider this scenario:
class Base
{
	// ...
}

class Derived : Base
{
	// ...
	
	FILE *f;
	
	this()
	{
		f = fopen(...);
	}
	
	~this()
	{
		fclose(f);
	}
}

void main()
{
	Base *b = new Derived();
	delete b; // call the copy constructor
	
	b = // something else...
}


Having a destructor and that you know when is going to be called 
is VERY useful!
So by removing the "delete" keyword, what happens? We won't have 
a way to destroy objects in a predictable way anymore? (I'm not 
talking about structs in any way).

Thanks


More information about the Digitalmars-d-learn mailing list