Hi everyone.
I 'got itno something strange in the following code:
class SomeClass {
public:
using byte = unsigned char;
void loadBuffer(std::string fileName);
private:
std::vector<std::array<byte, 100>> buffer;
}
In this simple class i declared a vector of arrays. This is because i want to read the file in blocks of 100 bytes. I know that there will always be complete 100 bytes blocks.
I tried to read the file this way:
void loadBuffer(...)
{
...
for (i = 0; i < blocks; i++)
{
buffer.push_back(std::array<byte, 100> {});
file.read(static_cast<char *>(&mRom[i][0]), 100);
}
...
}
but this gives me an error when trying to compile. It says something about invalid static cast from std::array... aka{unsigned char *} to char*.
I thought static_cast was supposed to help in this situations.
After some tweaking i found that old C fasion cast actually works:
file.read((char*)&mRom[i][0], 100);
I also discovered that reinterpret_cast works too.
I know that reinterpret_cast should be used the least possible and old-style C cast should not be used anymore.
Can anyone explain me what's going on?