Win10SysProgBookSamples icon indicating copy to clipboard operation
Win10SysProgBookSamples copied to clipboard

RAII for Handles (Modificated Version) in Chapter02

Open shalala66 opened this issue 1 year ago • 0 comments

Modification kindred with addings (all tested in Visual Studio 2019):

  1. "noexcept" operator to the necessary operations, such as destructor, move constructor and move assignment operator. Due to there was generates warning C26439: https://learn.microsoft.com/en-us/cpp/code-quality/c26439?view=msvc-170#:~:text=Special%20kinds%20of%20operations

Importance of adding noexcept operations: https://en.cppreference.com/w/cpp/language/operators#:~:text=%26%26%20other)-,noexcept,-%7B%0A%20%20%20%20//%20Guard%20self

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-noexcept:~:text=low%2Dlevel%20functions.-,Note,-Destructors%2C%20swap

https://en.cppreference.com/w/cpp/language/noexcept#:~:text=The%20noexcept%20operator%20performs%20a,some%20types%20but%20not%20others.

  1. The main function have to return type an "int" in general, because of that is why there was a compile error C2561 which solved via changing the "return;" line to "return 1;" for int main() function: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2561?view=msvc-170&f1url=%3FappId%3DDev16IDEF1%26l%3DRU-RU%26k%3Dk(C2561)%26rd%3Dtrue

https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4326?view=msvc-170&f1url=%3FappId%3DDev16IDEF1%26l%3DRU-RU%26k%3Dk(C4326)%26rd%3Dtrue

  1. The "Get()" method was replaced with "operator()" overloading related with adding implicit conversion to HANDLE as you mentioned: HANDLE operator()() const { return _h; }

Note: These commits - "RAII for Handles (original and modificated)" - have been PR to original repo but still have not been merged.

shalala66 avatar Nov 13 '23 15:11 shalala66