Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAII for Handles (Modificated Version) in Chapter02 #18

Open
shalala66 opened this issue Nov 13, 2023 · 0 comments
Open

RAII for Handles (Modificated Version) in Chapter02 #18

shalala66 opened this issue Nov 13, 2023 · 0 comments

Comments

@shalala66
Copy link

shalala66 commented Nov 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant