2013年2月14日木曜日

typedefされている型が,同じかどうか調べる

typedefされている型が,同じかどうか調べる.
typeidを使う.
typeinfoをインクルードする.


#include <iostream>
#include <typeinfo>
typedef int type_a;
typedef int type_b;
typedef short type_c;
int main(int argc, char **argv)
{
  if (typeid(type_a) == typeid(type_b)) {
    std::cout << "same" << std::endl;
  } else {
    std::cout << "different" << std::endl;
  }
  if (typeid(type_a) == typeid(type_c)) {
    std::cout << "same" << std::endl;
  } else {
    std::cout << "different" << std::endl;
  }
  return 0;
}

0 件のコメント:

コメントを投稿