Code: Select all
for (list<baseObject*>::const_iterator iter = base_m.begin(); iter != base_m.end(); ++iter)
Code: Select all
for (list<baseObject*>::const_iterator iter = base_m.begin(); iter != base_m.end(); ++iter)
Ripping this up into short bits of code:Neo wrote: Can anyone explain what this code means?I had a look andCode: Select all
for (list<baseObject*>::const_iterator iter = base_m.begin(); iter != base_m.end(); ++iter)
Code: Select all
list<baseObject *>::const_iterator iter;
for (iter = base_m.begin(); iter != base_m.end(); ++iter) {...}
Code: Select all
list<baseObject*>::const_iterator iter;
Code: Select all
for (list<baseObject*>::const_reverse_iterator iter = base_m.rbegin(); iter != base_m.rend(); ++iter)
Reverse iteration I guess.Solar wrote:Code: Select all
for (list<baseObject*>::const_reverse_iterator iter = base_m.rbegin(); iter != base_m.rend(); ++iter)
By behind did you mean 'next' or 'previous'?Solar wrote: [tt]base_m.begin()[/tt] gives you an iterator pointing to the first element, [tt]base_m.end()[/tt] gives you an iterator pointing to an element - be careful now - one behind the last element in the container. That means, dereference [tt]base_m.end()[/tt], you die.
Code: Select all
void* data = buff.Data();
pRaw = new (data) RawMsgHdr; //what does this mean?
Dito for me. It's also hard to consider any real situation in which you would want to do that. There are a few however, some of which are in OS development. IIRC, they do make changing your objects hard since placement new commonly indicates non-c++-aware software interacting with your software, which means that you cannot change the class instancevariable ordering or virtual functions by any extent.Solar wrote: Pretty obscure mojo which I haven't seen used "in the wild" before.
So could this actually be done with aSolar wrote: That's a "placement new". A RawMsgHdr object is created at the memory position that data points at. Pretty obscure mojo which I haven't seen used "in the wild" before.
Code: Select all
pRaw= (RawMsgHdr*)data;
No. It's an explicit call for a constructor on a previously-allocated area. This only makes it a pointer but doesn't call the constructor.Neo wrote:So could this actually be done with aSolar wrote: That's a "placement new". A RawMsgHdr object is created at the memory position that data points at. Pretty obscure mojo which I haven't seen used "in the wild" before.instead??Code: Select all
pRaw= (RawMsgHdr*)data;