// 実行時型情報(RTTI)
// 動的に型を認識していることを確認
// (*) コンパイラオプションに /GR が必要です。
//  usage : cl /GX /GR rtti01.cpp

#include <iostream>
#include <typeinfo>

using namespace std;

class basic {
	int  i;
public:
	virtual void foo( ) {};
	// ...
};

class sub1 : public basic {
	int	ihoge;
	// ...
};

class sub2 : public sub1 {
	int ihogehoge;
	// ...
};


void print_type( basic *pBasic ) {
	cout << "type is : " << typeid( *pBasic ).name( ) << endl;
}


int
main( )
{
	basic	o_basic,*po;
	sub1	o_sub1;
	sub2	o_sub2;

	po = &o_basic;
	print_type( po );

	po = &o_sub1;
	print_type( po );

	po = &o_sub2;
	print_type( po );

	return 0;
}

/*
	関数print_type( ) はポインタからその型の情報を抽出しています。
	/GRオプションはデフォルトで無効となっています。注意あれ。
*/


// end of file