Can someone explain the following code snippet for me?
// Bind base object so we can compute offsets
// currently only implemented for indexes.
template<class DataObj> void BindAsBase(DataObj &rowbuf)
{
// Attempting to assign working_type first guarantees exception safety.
working_type = DTL_TYPEID_NAME (rowbuf);
working_addr = reinterpret_cast<BYTE*>(&rowbuf);
working_size = sizeof(rowbuf);
}
My problem is what is the result of sizeof(rowbuf)? Is it the length of DataObj or either the length of Byte*? why?
Another question: why there is a need to calculate offset of pointer? What is the usual use of it?
What is sizeof(working_addr) equal to?
sizeof(rowbuf) returns the length in bytes of an object of type DataObj.
Note that rowbuf is no pointer, but it is a reference which is quite a difference.
If you want to calculate the size of y DataObj pointer use sizeof(&rowbuf) or sizeof(DataObj*).