__CLASS__C++中是否有一个宏,它给出类似于__FUNCTION__宏的类名,它给出了函数名
我无法在任何地方找到这个看似简单的问题的答案.
以下C++函数是否使用RTTI?它当然不必,但我想知道是否有保证在编译时确定typeid.
template <typename T>
const char *getName()
{
return typeid(T).name(); // Resolved at compile time?
}
Run Code Online (Sandbox Code Playgroud) 为什么typeid(someType)不像sizeof(someType)那样是常量?
这个问题出现了,因为最近我尝试了类似的东西:
template <class T>
class Foo
{
static_assert(typeid(T)==typeid(Bar) || typeid(T)==typeid(FooBar));
};
Run Code Online (Sandbox Code Playgroud)
我很好奇为什么编译器在编译时知道类型的大小(sizeof),而不是类型本身(typeid)