N
none
I'm trying to figure out why this testing code do not work and produce
an error in VC++ when returning from the foo method.
here's the code:
class test {
public:
char* pPointer;
test (void) {
pPointer = (char *) malloc (sizeof(char));
}
~test () {
free (pPointer); // HEAP error! when returning from foo
}
test test::foo (void) {
test myfoo;
return myfoo;
}
};
...
test atest;
atest = atest.foo(); // HEAP error!
The pPointer seems to be already freed by foo, why is this? How
can I make this code work?
Thanks in advance
an error in VC++ when returning from the foo method.
here's the code:
class test {
public:
char* pPointer;
test (void) {
pPointer = (char *) malloc (sizeof(char));
}
~test () {
free (pPointer); // HEAP error! when returning from foo
}
test test::foo (void) {
test myfoo;
return myfoo;
}
};
...
test atest;
atest = atest.foo(); // HEAP error!
The pPointer seems to be already freed by foo, why is this? How
can I make this code work?
Thanks in advance