您的位置:首页 > 编程语言 > C语言/C++

C++如何输出类型信息

2015-04-15 16:31 92 查看
#include "stdafx.h"
#include <typeinfo>
using namespace std;

template<class T>
class Cat
{
public:
void eat()
{
printf("eat %s",typeid(T).name());
}
};

class Fish
{

};

int _tmain(int argc, _TCHAR* argv[])
{
Cat<Fish> cat;
printf("%s \n", typeid(cat).name()); // class Cat
cat.eat();//eat class Fish
getchar();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐