Recently I stumbled over this article on how to import dll libraries in modern C++. The code totally overwhelmed me, so I went through it line by line and tried to figure out its meaning. By now, I think I got it but one thing is still not clear to me:
class ShellApi {
DllHelper _dll{"Shell32.dll"};
/* ... */
};
class DllHelper {
public:
explicit DllHelper(LPCTSTR filename) : _module(LoadLibrary(filename)) {}
/* ... */
private:
HMODULE _module;
};
Why is the instantiation DllHelper _dll{"Shell32.dll"}
written with curly brackets instead of normal ones? I tried it out in Visual Studio and had to realize that this snippet does not work with normal brackets. Why not? How is this kind of instantiation called (so I can look it up later)? Are there other scenarios where this is used?
If the code I provided is not enough to answer the question, the whole code is available in the article.