15 class A {
public:
virtual ~A(){} };
16 class B :
public A {
public:
void f(
bool verbose) {
if(verbose) std::cout <<
"\nB::f() called!\n"; } };
17 class C :
public A {};
19 int main(
int argc,
char* argv[] )
31 CommandLineProcessor clp(
false);
32 clp.setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
33 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
34 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
return parse_return;
39 <<
"\n*******************************************"
40 <<
"\n*** Basic test of Teuchos::dyn_cast<>() ***"
41 <<
"\n*******************************************\n";
45 if(verbose) std::cout <<
"\nTrying: dynamic_cast<C&>(a); [Should throw a std::bad_cast std::exception with very bad error message]\n";
46 C& c_from_an_a =
dynamic_cast<C&
>(a);
49 catch(
const std::bad_cast &e ) {
50 if(verbose) std::cout <<
"\nCaught std::bad_cast std::exception e where e.what() = \"" << e.what() <<
"\"\n";
53 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";
56 catch(
const std::bad_cast &e ) {
57 if(verbose) std::cout <<
"\nCaught std::bad_cast std::exception e where e.what() = \"" << e.what() <<
"\"\n";
59 if(verbose) std::cout <<
"\nTrying: Teuchos::dyn_cast<B>(a).f(); [Should succeed and print \"B::f() called\"]\n";
61 if(verbose) std::cout <<
"\nAll tests check out!\n";
63 catch(
const std::exception &excpt ) {
65 std::cerr <<
"*** Caught standard std::exception : " << excpt.what() << std::endl;
70 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.