I am studying the Rule of Zero and have 2 questions for the final piece of code which demonstrates the rule.
class module {
public:
explicit module(std::wstring const& name)
: handle { ::LoadLibrary(name.c_str()), &::FreeLibrary } {}
// other module related functions go here
private:
using module_handle = std::unique_ptr<void, decltype(&::FreeLibrary)>;
module_handle handle;
};
Why a curly bracket usage instead of parentheses to initialize handle?
It's uniform initializing method introduced in C++11
What does using module_handle = std::unique_ptr; mean exactly in this context? would it be possible to replace it with a typedef?
It's template aliasing and also for creating new type. using
is a new and powerful replacement of typedef