I have a set of pointers to image block objects. I have a derived class member function that returns a pointer to one of these image blocks, it is a virtual function so I can't change the return type without breaking everything.
Here is what I have so far:
ImageBlock* objArray = static_cast<ImageBlock*>( ::operator new ( sizeof ImageBlock * 256 ) );
for ( int i = 0; i < 256; i++ )
new (&objArray[i]) ImageBlock(blkh, blkw, 0.0);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
ImageBlock* temp = getNewBlock(i, j, Image); // getBlock returns ImageBlock*
objArray[i*16 + j] = *temp;
delete temp;
}
}
As you can see this is a terrible solution. I'd like to assign the pointer directly using some pointer arithmetic like so:
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
(objArray+(i*16 + j)) = getNewBlock(i, j, Image);
}
}
However I get the error expression must be a modifiable lvalue with objArray underlined in red. I know it would work the other way around taking a pointer from the array. I've searched the error and I keep seeing things like "you can't assign to arrays" well it isn't an array in the conventional sense is it? I have a few thoughts on why it won't work but I would like to know for sure. If anyone could offer up a better solution that would be interesting.
Thanks
Ivalue, you meanlvalue.