Shouldn't Gdiplus :: Image :: GetWidth () and many other getters be "const"?

Why aren't they const?

I believe that the API design is wrong. Or am I missing something?

UINT GetWidth(); UINT GetHeight(); ... 

vs.

 UINT GetWidth() const; UINT GetHeight() const; ... 
+4
source share
3 answers

Hard to say. I would agree, but maybe there is something in the implementation that prevents them from being const , and that they do not want to add overhead to hide. We currently have the mutable keyword, but I think it is younger than this API.

Or maybe the API developers belong to the (sometimes stunningly large, imo) group of C ++ developers who are hostile to the const keyword, feeling that this only complicates the work. I am not a Windows historian, so I can’t tell you. :)

+2
source

Wrong API design? C ++ style headers? From the teams that brought us CString ? No, it can not be...

Seriously, however, don't expect the GoTW level of using C ++ in any Win32 API or more than the base shell around the C-style handle. Herb Sutter was busy with .NET: ing C ++, and did not improve the design of the Microsoft library. WTL is so close that I saw how Microsoft came to modern C ++ , and this led to a rather obscure existence.

+4
source

Strictly speaking, you are probably right - the variable must be const.

I assume you are talking about the native Gdiplus C ++ API. If you study the implementation of this code and the Gdiplus classes, you will find that most of the code is the basic shell of the Gdiplus Flat API functions ( http://msdn.microsoft.com/en-us/library/ms533969(VS.85).aspx ) . This can make it difficult to make the code const-correct ... or (as I have already hinted) that Microsoft, as a rule, is not very modern C ++.

EDIT: Looking at the code for Gdiplus :: Image :: GetWidth () (in GdiPlusBitmap.h), it would be easy for MS to implement many functions with the const modifier. They did this with Image :: GetType (), and the code inside is pretty much identical to Image :: GetWidth (), Image :: GetHeight ().

+1
source

All Articles