Skip to content

Instantly share code, notes, and snippets.

@OdNairy
Last active December 18, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OdNairy/5813364 to your computer and use it in GitHub Desktop.
Save OdNairy/5813364 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class A{
protected:
int i;
public:
A():i(0){ cout << "A" ; }
A(A& ob){ cout << "B"; }
~A(){ cout << "C"; }
void fun(){ cout << "D"; }
};
class B: public A{
public:
B(){ cout << "E"; }
B(B& ob){ cout << "F"; }
~B(){ cout << "G"; }
int get(){ return i; }
};
A* fun(B& ob){
if ( !ob.get() )
throw ob;
return &ob;
}
int main(int argc, char* argv[]){
B ob;
try{
fun(ob);
}
catch(B& ob){
cout << "W";
}
catch(A& ob){
cout << "O";
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment