I have a number objects which hold std::functions, but not all objects will have a target function. For example if I have a set of windows and each window may or may not have behaviours set for certain events.
I found out that you can check if an std::function has a target by doing either:
std::function<void()> fnptr;
if (fnptr) // then;
//OR
if (fnptr != nullptr) // then;
as this class has conversion operators for bool and nullptr_t. But I'm wondering is there a way to specifically initialise this class to say "I want you to be a null pointer for now", as I would usually do for:
int (*fnptr)() = nullptr; // To make sure it's null for when I do checking.
Or is this assumed when creating an std::function object with the default constructor?
Aucun commentaire:
Enregistrer un commentaire