47 class A {
public:
virtual ~A(){} };
48 class B :
public A {
public:
void f(
bool verbose) {
if(verbose) std::cout <<
"\nB::f() called!\n"; } };
49 class C :
public A {};
51 int main(
int argc,
char* argv[] )
63 CommandLineProcessor clp(
false);
64 clp.setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
65 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
66 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
return parse_return;
71 <<
"\n*******************************************"
72 <<
"\n*** Basic test of Teuchos::dyn_cast<>() ***"
73 <<
"\n*******************************************\n";
77 if(verbose) std::cout <<
"\nTrying: dynamic_cast<C&>(a); [Should throw a std::bad_cast std::exception with very bad error message]\n";
78 C& c_from_an_a =
dynamic_cast<C&
>(a);
81 catch(
const std::bad_cast &e ) {
82 if(verbose) std::cout <<
"\nCaught std::bad_cast std::exception e where e.what() = \"" << e.what() <<
"\"\n";
85 if(verbose) std::cout <<
"\nTrying: Teuchos::dyn_cast<C>(a); [Should throw a std::bad_cast std::exception with a very good error message]\n";
88 catch(
const std::bad_cast &e ) {
89 if(verbose) std::cout <<
"\nCaught std::bad_cast std::exception e where e.what() = \"" << e.what() <<
"\"\n";
91 if(verbose) std::cout <<
"\nTrying: Teuchos::dyn_cast<B>(a).f(); [Should succeed and print \"B::f() called\"]\n";
93 if(verbose) std::cout <<
"\nAll tests check out!\n";
95 catch(
const std::exception &excpt ) {
97 std::cerr <<
"*** Caught standard std::exception : " << excpt.what() << std::endl;
102 std::cerr <<
"*** Caught an unknown std::exception\n";
Initialize, finalize, and query the global MPI session.
T_To & dyn_cast(T_From &from)
Dynamic casting utility function meant to replace dynamic_cast<T&> by throwing a better documented er...
std::string Teuchos_Version()
int main(int argc, char *argv[])
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
Class that helps parse command line input arguments from (argc,argv[]) and set options.