TBuf(C) & HBufC
TBuf is meant to be used on stack or within the data section of another object. It doesn` t need a destructor the same as any other T classes. However, we still can write code like this:
TBuf<1>* buf = new (ELeave) TBuf<1>();
actually, we can allocate memory for any T class on heap. a quick fix to this is to overload operator new as private
HBufC faces the same problem, though it s 100% sure that any HBufC object is on heap, because the constructor is defined as private and several static function are provided to return the pointer of a new object, but we can still try something bad
HBufC buf = *HBufC::NewL(1);
and what s worse is that we can not write delete &buf.
To make sure HBufC is on heap, and we can` t write code above, we need to declare destructor as private also, and add another public function to release the HBufC object