此函数的返回类型是什么

What is the return type of this function?

本文关键字:是什么 返回类型 函数      更新时间:2023-10-16

我把这一行放进了类的宏观定义中

virtual const char *GetEventName() const
{
    return #classname;
}

此函数及其返回类型中发生了什么?

如果classname是宏的参数之一,则#classname是其值的字符串版本。所以如果classname SomeType#classname相当于"SomeType"

由于它返回一个字符串(c 字符串),因此返回类型为 const char*

有关更多信息,请查看字符串化