Not sure if the title is right or not, but here it goes:
If I have for example the following structure:
struct strA{
int x;
strA(int x);
}
strA::strA(int x){
this->x = x;
}
And another structure that uses a pointer to the previous one:
#include strA
struct strB{
int y;
strA *var_strA;
strB(int y);
~strB(){
delete var_strA;
}
};
strB::strB(int y){
this->y = y;
var_strA = new strA(123);
}
Then if I do from the main aplication a vector of strB items:
std::vector<strB> vectB;
main(){
strB *itemB = new strB(456);
vectB.push_back(*itemB);
delete itemB;
//more code
}
If I try to access the var_strA on the item in the vector, is empty. And also, I get an error when by deleting the item on the vector, since the destructor tries to delete var_strA again.
Comming from Java... I'm really getting lost with the damn pointers.
thanks in advance