anonymus struct or class instances as arguments
Leopold Walkling
leopold_walkling at web.de
Thu Dec 7 13:04:19 PST 2006
Couldn't there be a syntax for creating a struct or class instance, that
only exists for one function?
In the moment there are scope classes, but they can't be used without an
identifier as an argument. Normal class instances can be given as an
argument, but then the destructor can't be called manually, nor is it
called automatically before the end of the programm.
Why can't the 'scope' keyword be used like this:
function(scope new A() // Here the constructor is called);
//Here the destructor is called
Also there isn't a way to create a struct, only by giving its values.
This can be done with something like this, although it's very ugly:
struct A {
int i;
}
void funk(A);
int main() {
funk(*(cast(A*)[cast(int)9].ptr);
return 0;
}
Also this would lead to a slight overhead, because of the cast. Is there
any reason why those possibilites don't exist?
And what should I use instead of those, if they are refused?
My main problem is, that I don't want to create a variable with a name
everytime I have to use one Object, that I don't need later, and then
call the destructor.
More information about the Digitalmars-d
mailing list