Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Base {
- public:
- virtual ~Base() {
- cout << "~Base()\n";
- }
- };
- class Derived : public Base {
- ~Derived() override {
- cout << "~Derived";
- }
- };
- int main() {
- Base *obj = new Derived();
- try {
- throw *obj;
- } catch (Derived& a) {
- cout << "caught derived\n";
- } catch (Base& a) {
- cout << "caught base\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement