Skip to content

Instantly share code, notes, and snippets.

@Tocchann
Last active October 6, 2021 13:28
Show Gist options
  • Save Tocchann/14ac820a05153fb1aa67cdabddf149c1 to your computer and use it in GitHub Desktop.
Save Tocchann/14ac820a05153fb1aa67cdabddf149c1 to your computer and use it in GitHub Desktop.
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