#include "factories.h" #include "../../cmm/dispatch.h" #include #include namespace { void Show( std::exception& e) { std::cerr << "Caught exception: " << e.what() << "\n"; } } int main( int argc, char** argv) { try { (void) argc; std::cerr << argv[0] << " started...\n"; Shape& s = *MakeSquare(); Shape& t = *MakeTriangle(); try { Overlap( t, 0, t, 0); // Throws - no matching implementation throw std::runtime_error( "Overlap( t, t) should have thrown"); } catch( cmm_exception_unmatched& e) { std::cerr << "caught expected exception: " << e.what() << "\n"; } try { Overlap( s, 0, t, 0); // Calls Overlap_( Square&, Triangle&) } catch( std::exception& e) { throw std::runtime_error( "Overlap( s, t) threw, but should have been successful"); } try { Overlap( t, 0, s, 0); // Calls Overlap_( Triangle&, Square&) } catch( std::exception& e) { throw std::runtime_error( "Overlap( t, s) threw, but should have been successful"); } try { Overlap( s, 0, s, 0); // Throws - no best matching implementation throw std::runtime_error( "Overlap( s, t) should have thrown"); } catch( cmm_exception_ambiguous& e) { std::cerr << "caught expected exception: " << e.what() << "\n"; } return 0; } catch( std::exception& e) { std::cerr << "Error: " << e.what() << "\n"; } return 1; }