아마 이런거는 이미 있을꺼고. 아마 stl 기본 라이브러리가 있겠지만
난 모르겠고, 그래서 그냥 간단하게 만들어봤다. 예제는 아래와 같다.
#include <iostream>
using namespace std;
template<typename T>
void type_of(T t)
{
cout << "normal" << endl;
}
template<>
void type_of(int t)
{
cout << "int" << endl;
}
template<>
void type_of(float t)
{
cout << "float" << endl;
}
template<>
void type_of(double t)
{
cout << "double" << endl;
}
int main()
{
auto i = 1.0;
type_of(i);
auto p = 1;
type_of(p);
int y = 0;
type_of(y);
return 0;
}
실행해보면
double
int
int
잘 나온다. 그냥 템플릿 특수화를 이용해봤다. 어디다가 쓸지는 당장 생각나지
않지만 필요할것 같다. enum 타입으로 리턴하면 더 좋을 것이다.
끗
읽지는 않았지만 좋은글 같읍니다
#include <typeinfo>
typeid( some_instance ).name() 을 참고하길 바란다.
흠