C++ Storage Copy Byte by Byte? -
i'm learning c++ book thinking in c++. there paragraph of codes don't understand. it's member function of struct holds array of chars or integers. add function supposed add each element: char or int.
int stach::add(const void* element){ int startbytes=next*size; //according book, next next space available , size size of space unsigned char* e=(unsigned char*)element; for(int i=0; i<size;i++) storage[startbytes+i]=e[i]; next++; return(next-1);// return index }
the part don't understand space, size of space? book didn't explain is. also, i'm confused with
unsigned char* e=(unsigned char*)element; for(int i=0; i<size;i++) storage[startbytes+i]=e[i];
my understanding of function copies, int, occupies 4 bytes, byte byte? understanding correctly? how interpret
unsigned char* e=(unsigned char*)element;
thanks lot.
c++ models of program memory array of bytes (characters, unsigned characters). legally allowed inspect representation of object byte-by-byte casting pointer object (usually unsigned
) char*
.
what code doing, using array of bytes sort-of type-independent storage space. when call add
, copies byte representation of object added internal array of bytes storage
. how 1 might implement type-independent container in c, inappropriate c++, in 2000.
Comments
Post a Comment