C++如何输出类型信息

#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;
}
posted @ 2015-04-15 16:31  河豚  阅读(480)  评论(0编辑  收藏  举报