For example I Have this example code:
class Player
{
int grid;
Player()
{
grid = 0;
}
}
void main()
{
Player p;
...
...
//now again I want to initialize p here, what to write ?
}
How do I call the constructor of p again ?
Add
init
function. Call it in constructor, but also make it public, so you can call it later again.Actually you can make any function you want to change the state:
Put the object into a local scope:
Each time the loop body executes, a new
Player
object is instantiated.Reinforcing Andrew's answer: