I have an object declaration Bitmap image(FileRead(filename))
that is ... really confused?
When I hover over filename
in Visual Studio, it gives me the tooltip FileRead filename
as if I were declaring a new variable in the parameter list. When I hover over image
it gives me Bitmap image(FileRead filename)
as if it were a function declaration. These are my only clues as the compiler only gives me a compilation error if I attempt to use one of image's methods, confirming that image
at least isn't being interpreted as an object.
If I change the argument so it's Bitmap image(FileRead("strLiteral"))
or if I add a second optional argument so it's Bitmap image(FileRead(filename), 4)
, the problem goes away. Maybe one of the other constructors is confusing it but... I'm fairly sure that type of ambiguity is it's own class of compilation error, what I'm getting is totally different?
I'm genuinely mystified, what could be going on here?
int main(int argc, char * argv[]){
const char * filename = "image.png";
Bitmap image(FileRead(filename));
// using either of these instead works as intended for some reason
Bitmap image(FileRead(filename), 4u);
Bitmap image(FileRead("image.png"));
// image.get*() generates the following compilation error:
// "Error C2228 left of '.getY' must have class/struct/union"
// "Error C2228 left of '.getX' must have class/struct/union"
for (uint32 y = 0; y < image.getY(); ++y) {
for (uint32 x = 0; x < image.getX(); ++x) {
}
}
return 0;
}
Here's all of the constructor signatures to FileRead and Bitmap, in case something in here was causing trouble.
class Bitmap {
friend Mipmaps;
public:
Bitmap();
Bitmap(const Bitmap & other, bool flipY = false);
Bitmap(Bitmap && other, bool flipY = false);
Bitmap & operator=(const Bitmap & other);
Bitmap & operator=(Bitmap && other);
Bitmap(FileRead & file, uint16 byteDepth = 4u, uint16 heightForVolume = 0, bool flipY = false);
Bitmap(const uint8 * compressedImgData, uint32 imgDataLen, uint16 byteDepth, uint16 heightForVolume = 0, bool flipY = false);
Bitmap(uint16 byteDepth, glm::u16vec2 size);
Bitmap(uint16 byteDepth, glm::u16vec3 size);
static Bitmap asBorrowed(uint8 * data, glm::u16vec4 size, TextureDim::Type dimensionality = TextureDim::dim2D);
...
uint16 getX() const { return m_size.x; }
uint16 getY() const { return m_size.y; }
};
class FileRead{
public:
FileRead(const char * filename, bool textMode = false, uint32 bufferSize = 4096);
...
};