View Single Post
Old 04-13-2010, 05:03 AM   #34
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Quote:
Originally Posted by Astralp View Post
Well I tried using put() first, but could not get it to work for ints, and my lack of understanding for templates led me to just copy the put() code in my above functions.
The beauty of the template class stuff is that, even if you don't know much about it, you can still use it. You can simply do:

Code:
int mMyInt = 12345;
...
pChunk->Put(&mMyInt);

Quote:
Originally Posted by Astralp View Post
I'm not sure about sizeof pointer, but I think that is how it is in put isn't it? Can't check at the moment.
No, ByteChunk::Put() does sizeof(T), not sizeof(pVal):

Code:
template <class T> inline int Put(const T* pVal) 
{
	int n = mBytes.GetSize();
	mBytes.Resize(n + sizeof(T));
	memcpy(mBytes.Get() + n, (BYTE*) pVal, sizeof(T));
	return mBytes.GetSize();
}
Tale is offline   Reply With Quote