What does typedef Class *(createClassFunction)(void)
(or another variation is typedef Class* (__stdcall *CreateClassFunction)(void)
)stand for?
What does it mean? How am I supposed to explain it?
Especially in the context of Factory Patterns...
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Reading C type expressions
createClassFunction
is a typedef for a function taking no arguments and returning aClass *
.With that declaration, a pointer to such a funciton can obviously act as factory for a
Class
. Usage might be as follows:__stdcall
is a compiler specific attribute changin the calling convention (how parameters and return value are passed between caller and implementation). This is often important for binary compatibility - e.g. when a Pascal program needs to call a funciton imlemented in C or C++.Issues:
The factory function returns a raw pointer. There must be an implicit contract between the factory and the consumer how to free that pointer (e.g. through
delete
in or example). Using a smart pointer (e.g. shared_ptr) for the return type would allow the factory to determine the deletion policy.The factory, as a function pointer, may not hold state (such as the log file name, it needs to be hard coded in the function, or available globally). using a callable object instead would allow to implement configurable factories.