I want to reinitialize (delete previous object and its data) on each iteration.
I am not using new operator to create class objects and also my destructor has nothing in its body. My project has a following structure.
-- "A.h"
class A
{
A();
~A();
.....
}
--- "B.h"
include"A.h";
class B::A
{
B();
~B();
void doSomthing();
.....
}
"myproject.cpp"
include "B.h"
void main()
{
...
for( ...)
{
B objectB;
B.doSomthing();
}
}
In my case this structure remains all the previous values in class A and class B. so, on next iteration it uses the previous values. But i think as i am recreating object so, it should create everything new.
What are you doing in constructors? Are you initialize class members (by zero for example)? If not then class members will be recreated at the same place in stack and will be have the same values at each iteration. The same is true for local uninitialized variables in doSomthing().