有人可以爲我解釋下面的代碼片段嗎?C++中的Sizeof以及如何計算指針長度?
// 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);
}
我的問題是什麼是sizeof(rowbuf)的結果?它是DataObj的長度還是Byte *的長度?爲什麼?
另一個問題:爲什麼需要計算指針的偏移量?它通常使用什麼?
什麼是sizeof(working_addr)等於?
這將有助於有更多的上下文。通常,您不使用C++中的reinterpret_cast和sizeof,而使用非標準的typeid函數。 這段代碼進入了什麼?這個信息用於什麼? – Potatoswatter 2009-09-13 15:16:04