// 511 2003-02-11
$ cat copy.cpp
#include
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
class array
{
protected:
int
size;
int
*data;
public:
array(int sz)
{ size=sz;
data=new int[sz]; }
~array(void)
{ delete[] data;
}
int
getsize(void)
{ return size; }
int
get(int i)
{ if (i<0 || i>=size) return -1;
return data[i]; }
void set(int i, int
val)
{ if (i>=0 && i<size)
data[i]=val; } };
void check(array a)
{ for (int i=0; i<a.getsize(); i+=1)
if (a.get(i)==73)
printf("bad array\n"); }
void main(void)
{ array x(100);
for (int i=0; i<100;
i+=1)
x.set(i, random());
check(x);
for (int i=0; i<10;
i+=1)
printf(" %d", x.get(i));
printf("\n"); }
$ CC
copy.cpp
$ a.out
a.out in free(): warning: page is
already free
1804289383 959984180 540227635 960050489
942748728 875896880 926036528 540357430 808465977 942944309