Last active
October 6, 2021 13:28
-
-
Save Tocchann/14ac820a05153fb1aa67cdabddf149c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassA | |
{ | |
public: | |
static bool IsValidHandle( HANDLE handle ) | |
{ | |
//return handle != INVALID_HANDLE_VALUE; | |
return handle != INVALID_HANDLE_VALUE && handle != nullptr; | |
//return handle != nullptr; | |
} | |
// ハンドルの複製をどうするかは何のハンドルかに依存するのでここでは言及しない | |
ClassA( const ClassA& ){ ... } | |
ClassA& operator=( const ClassA& ){ ... } | |
ClassA() | |
: p( nullptr )// INVALID_HANDLE_VALUE | |
{ | |
} | |
~ClassA() | |
{ | |
Uninitialize(); | |
} | |
bool Initialize() | |
{ | |
// Uninitialize(); | |
if( IsValidHandle( p ) ) | |
{ | |
// すでに初期化済みの場合は成功扱い(失敗なりリセットなりもある) | |
return true; | |
} | |
// ここでクラスのインスタンスの初期化を行う | |
return IsValidHandle( p ); | |
} | |
void Uninitialize() | |
{ | |
if( IsValidHandle( p ) ) | |
{ | |
// ハンドルを破棄する | |
p = nullptr; // INVALID_HANDLE_VALUE | |
} | |
} | |
private: | |
HANDLE p; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment