在下面这个玩具示例中,我想获取函数的名称。该函数本身作为
std::function
参数给出。在C++中是否有可能获得std::function
对象的名称?void printName(std::function<void()> func){
//Need a function name()
std::cout << func.name();
}
void magic(){};
//somewhere in the code
printName(magic());
output: magic
否则,我将不得不将函数名称作为第二个参数给出。
std::function
不需要封装任何具有名称的内容... - Kuba hasn't forgotten MonicaprintName(magic());
无法编译。 - user253751