C/C++ Coding Tips
Filter::Filter() { buf = 0;}Filter::AllocateBuffer(int n) { buf = new int [n];}Filter::DeallocateBuffer() { if (buf) delete buf;}Filter::~Filter() { DeallocateBuffer();}
Filter::AllocateBuffer(int n) { DeallocateBuffer(); buf = new int [n]; if (buf == 0) { cerr << “allocation failed”; exit(0); } memset(buf, 0, n* sizeof(int));}Filter::DeallocateBuffer() { delete [] buf; buf = 0;}
Robust (keep constructorand destructor)