Hello guys,
I wanna ask a question related with memory management.
I many times allocate memory (for ex. int a = new int) but don't delete them in a C++ Class.
So how to control it?
In simple procedure programs, I know to make a free of the memory (by delete function), however, I am not able to use it in Classes.
yeah, thank you very much guys. I did as you showed. And still i feel lack of skill on programming languages.
So, what about a condition below:
struct sA{
int x;
}
Class A{
public:
void funcA(vector<sA*>);
int *k;
};
A::A(){}
A::~A(){ delete k; }
void A::funcA(vector<sA*> vA){
sA* ssA = new sA;
for (k=0; k<10; k++)
{
ssA->x = k;
vA.push_back(ssA);
}
// here I deleted ssA but it gave me heap error
}
where should I delete ssA?
please help!
Thanks in advance.