在 C++ 中,当一个 std::function 对象不包含任何可调用的目标时,该对象就被视为 null 或 empty。默认情况下,当你默认构造一个 std::function 时,它确实是空的。这意味着它不指向任何函数或可调用对象。
In C++, an std::function object is considered null or empty when it doesn't contain any callable target. By default, when you default-construct an std::function, it is indeed empty. This means it doesn't refer to any function or callable object.
|
#include <iostream>
#include <functional>
int main() {
std::function<void()> func;
if (!func) {
std::cout << "The std::function object is null (empty)." << std::endl;
} else {
std::cout << "The std::function object is not null." << std::endl;
}
return 0;
}
Output:
The std::function