C++ typeid获取类型信息

#include <iostream>
#include <typeinfo>

int main()
{
   int i;

   const std::type_info &info = typeid(int);
   std::cout << "typeid " << info.name() << std::endl;

   if(info == typeid(i));
   {
      std::cout << "do something" << std::endl;
   }

   return 0;
}
$ ./a.out       
typeid i
do something
posted @ 2022-08-17 08:40  thomas_blog  阅读(28)  评论(0编辑  收藏  举报