Based on http://en.highscore.de/cpp/boost/smartpointers.html#smartpointers_shared_pointer
#include <boost/shared_ptr.hpp>
#include <windows.h>
int main()
{
boost::shared_ptr<void> h(OpenProcess(PROCESS_SET_INFORMATION, FALSE,
GetCurrentProcessId()), CloseHandle);
SetPriorityClass(h.get(), HIGH_PRIORITY_CLASS);
}
Question:
Why the h
is defined as boost::shared_ptr<void>
rather than boost::shared_ptr<HANDLE>
?
FYI:
WINBASEAPI
HANDLE
WINAPI
OpenProcess(
__in DWORD dwDesiredAccess,
__in BOOL bInheritHandle,
__in DWORD dwProcessId
);
typedef void * HANDLE;
http://www.boost.org/doc/libs/1_47_0/libs/smart_ptr/sp_techniques.html#pvoid
Because a boost::shared_ptr<HANDLE>
would be a boost::shared_ptr<PVOID>
, which is a boost::shared_ptr<void*>
- which is, obviously, different than boost::shared_ptr<void>
. Notice the extra pointer.
If you had a boost::shared_ptr<HANDLE>
, it would essentially be a smart pointer to a pointer to void
, as opposed to a smart pointer to void.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With