#include <iostream.h>
#include <windows.h>
int
main(int, char **)
{
int *ptr1 = new int; //Allocate an int
int *ptr2 = ptr1; //Bug: should duplicate object,
not copy pointer to the object
*ptr1 = 10;
*ptr2 = 20; //Overrides assignment of 10
cerr << "ptr1" << " is " << *ptr1 << '\n';
cerr << "ptr2" << " is " << *ptr2 << '\n';
delete ptr1;
delete ptr2; //FFM: already freed by the line above
return(0);
}
(C) Copyright IBM Corporation 1992, 2010.