아무거나? 막 집어 넣을 수 있는 Boost::Any 입니다~
콘솔 프로젝트를 시작한 후 소스를 그대로 replace 해서 테스트 하시면 됩니다.
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#pragma hdrstop
#include <list>
#include <boost/any.hpp>
#include <boost/shared_ptr.hpp>
using boost::any_cast;
using boost::shared_ptr;
typedef std::list<boost::any> many;
//---------------------------------------------------------------------------
class TZPacket
{
public:
TZPacket() {};
};
typedef boost::shared_ptr<TZPacket> ZPacket;
#pragma argsused
int main(int argc, char* argv[])
{
ZPacket a( new TZPacket() );
many mylist;
boost::any any = AnsiString("A1");
mylist.push_back(any);
any = a;
mylist.push_back(any);
many::iterator iter;
for( iter = mylist.begin(); iter != mylist.end(); iter++ )
{
/*
try
{
//any_cast<AnsiString>(*iter) ;
printf("%s\n", any_cast<AnsiString>(*iter) );
}
catch( Exception &e )
{
printf("Error\n");
break;
}
catch( const boost::bad_any_cast & )
{
printf("boost::bad_any_cast\n");
}
*/
if( (*iter).type() == typeid(ZPacket) )
{
printf("index %d = ZPacket\n", iter);
}
if( (*iter).type() == typeid(AnsiString) )
{
printf("index %d = AnsiString\n", iter);
}
}
system("pause");
return 0;
}
//---------------------------------------------------------------------------
|