Here's what I had:
// define structures A & B...
// Brief example of the functions:
struct B* foo(const struct A mystruct)
{
struct B *outstruct = new S();
// Copying values from structure A to B
return(outstruct);
}
int main()
{
struct A *mystruct = new A();
struct B *tmp = foo(*mystruct);
delete(A); delete(B);
return 0;
}
I kept getting a core dump message, so I put a printf statement in the destructor of A. It showed that the destructor was called twice: (1) at the end of main, as expected, and (2) at the end of foo.
So, I changed the foo function to pass mystruct as a pointer (making the necessary syntax changes) and the destructor was called only once, at the end of main as desired. What is the reason for this? Or might I be missing something else?