A
Alexander Malkis
A real-life example:
int alpha_beta(unsigned depth,Position p, Move& m /*,other args*/) {
//...do smth with p
if(depth) {
Move m;
int val=alpha_beta(depth-1,p,m /*,other args*/);
}
//...
//sometimes change m, e.g.:
if(depth==global_depth) m=best_move;
//...return...
}
The problem here is that the (perhaps, default) constructor for m is
called. It may do as little as he wish, but nevertheless he inits all
the members of Move. It's time-consuming. But we don't need initializing
at all, since the "Move m" declaration is needed only to let the
recursively called fucntion sometimes change m.
In C, if M were a struct, no init were performed and we had no problem.
But what to do in C++ without too much hack?
int alpha_beta(unsigned depth,Position p, Move& m /*,other args*/) {
//...do smth with p
if(depth) {
Move m;
int val=alpha_beta(depth-1,p,m /*,other args*/);
}
//...
//sometimes change m, e.g.:
if(depth==global_depth) m=best_move;
//...return...
}
The problem here is that the (perhaps, default) constructor for m is
called. It may do as little as he wish, but nevertheless he inits all
the members of Move. It's time-consuming. But we don't need initializing
at all, since the "Move m" declaration is needed only to let the
recursively called fucntion sometimes change m.
In C, if M were a struct, no init were performed and we had no problem.
But what to do in C++ without too much hack?