実行時型情報



コード

#include	<iostream>

#include	<typeinfo>

using namespace std;

class	Obj{

public:
	int	i;

};


//実行時型情報(テンプレート関数) intの場合"Bingo"を表示
template <class x> void Test(x A)
{
	cout << "----- Start Test -----" << endl;

	if(typeid(int) == typeid(A)){
		cout << "Bingo!! --> int" << endl;
	}else{
		cout << typeid(A).name() << endl;
	}

	cout << "----- End Test -----" << endl << endl;
	
	return;
}


void main()
{
	
	Obj	ObjClass;

	ObjClass.i = 1;

	Test(ObjClass);

	Test(ObjClass.i);
	
	return;	
}
			


結果

----- Start Test -----
class Obj
----- End Test -----

----- Start Test -----
Bingo!! --> int
----- End Test -----
			

ビジネスPC&PCサーバ


<戻る>

楽天モバイル[UNLIMITが今なら1円] ECナビでポインと Yahoo 楽天 LINEがデータ消費ゼロで月額500円〜!


無料ホームページ 無料のクレジットカード 海外格安航空券 解約手数料0円【あしたでんき】 海外旅行保険が無料! 海外ホテル