//: C01:Covariance.cpp {-xo} // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // Should cause compile error. {-mwcc}{-msc} #include using namespace std; class Base { public: class BaseException {}; class DerivedException : public BaseException {}; virtual void f() throw(DerivedException) { throw DerivedException(); } virtual void g() throw(BaseException) { throw BaseException(); } }; class Derived : public Base { public: void f() throw(BaseException) { throw BaseException(); } virtual void g() throw(DerivedException) { throw DerivedException(); } }; ///:~