i am a bit confused..
i have two pointers, foo1 already has stuff in it, and i want to move the contents to foo2.
1 2 3 4 5 6 7 8 9 10
|
std::string *foo1 = ...has stuff....;
std::string *foo2;
..
..
memmove(foo2,foo1,sizeof(foo1));
..
cout<< foo2->c_str();
|
ABOVE WORKS!
however, i assume after the moving of content to mememory space of foo2, i can delete foo1 correct???
1 2 3 4 5 6 7 8 9 10 11 12
|
std::string *foo1;
std::string *foo2;
..
..
memmove(foo2,foo1,sizeof(foo1));
delete(foo1);
..
cout<< foo2->c_str();
|
Above doesn't work! foo2 is deleted as well, or empty....how do i move the foo1 to foo2, and able to delete foo1 because i dont neeed it anymore?
Thanks.
***Updated***, i didn't mean to type delete(foo2), what im saying is when i delete foo1, i try to access foo2->c_str() it doesn't work......
also, this is VERY simplified from what i am currently working on..so the code is Pseudocode..... in 'reality'
foo1
and
foo2
are
structs
, i am building up data in
foo1 struct
, when it is done filling up, i want to copy the content to
foo2
, but i want to delete the cotent of
foo1
because don't need it anymore. and don't want to huge struct with data in memory.