Why aren't they const?
I believe that's flawed API design. Or am I missing something?
UINT GetWidth();
UINT GetHeight();
...
vs.
UINT GetWidth() const;
UINT GetHeight() const;
...
Why aren't they const?
I believe that's flawed API design. Or am I missing something?
UINT GetWidth();
UINT GetHeight();
...
vs.
UINT GetWidth() const;
UINT GetHeight() const;
...
Hard to say. I'd agree, but perhaps there is something in the implementation that prevents them from being const
, and that they didn't want to add overhead to hide. Nowdays we have the mutable
keyword, but I think that is younger than this API.
Or maybe the designers of the API belong to the (sometimes shockingly large, imo) bunch of C++ developers who are hostile towards the const
keyword, feeling that only makes things harder to use. I'm no Windows historian, so I can't tell you. :)
Flawed API design? C-style C++ headers? From the teams who brought us CString? Nah, can't be...
Seriously, though, don't expect GoTW-level C++ usage in any Win32 API, or more than a basic wrapper around the C-style handles. Herb Sutter has been busy with .NET:ing C++ rather than improving Microsoft library design. The WTL is as close as I've seen Microsoft come to modern C++, and that has led a rather obscure existence.
Strictly speaking you are probably right - the variable should be const.
I'm assuming you are talking about the Gdiplus C++ native API. If you look into the implementation of this code and the Gdiplus classes you'll find that most of the code is a basic wrapper around the Gdiplus Flat API functions (http://msdn.microsoft.com/en-us/library/ms533969(VS.85).aspx). This might make it either difficult to make the code const-correct... or (as another hinted at) it's Microsoft being typically not-very-modern-C++.
EDIT: Looking at the code for Gdiplus::Image::GetWidth() (in GdiPlusBitmap.h), it would have been easy for MS to implement many of the functions with the const modifier. They've done it with Image::GetType() and the code inside is pretty much identical to Image::GetWidth(), Image::GetHeight().