Advertisement
Proff_Ust

Lab6

Dec 27th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. using namespace std;
  4. class Foo
  5. {
  6. private:
  7.     int number;
  8.  
  9. public:
  10.     Foo()
  11.     {
  12.         this->number = -1;
  13.     }
  14.     Foo(int newNumber)
  15.     {
  16.         if(newNumber==7)
  17.             throw 7;
  18.         else
  19.         {
  20.             this->number = newNumber;
  21.             cout<<"Номер создаваемого объекта "<<this->number<<endl;
  22.         }
  23.  
  24.     }
  25.  
  26.     ~Foo()
  27.     {
  28.         cout<<"Номер удаляемого объекта "<<this->number<<endl;
  29.     }
  30.  
  31. };
  32.  
  33. Foo globalVar(1);
  34. Foo fooArray[3] = {Foo(2), Foo(3), Foo(4)};
  35.  
  36. int main ()
  37. {
  38.     setlocale(LC_ALL,"RU");
  39.     Foo localVar(5);
  40.     static Foo staticVar(6);
  41.     Foo localFooArray[10];
  42.     for(int i=0;i<10;i++)
  43.     {
  44.         try
  45.         {
  46.             localFooArray[i] = Foo(i);
  47.         }
  48.         catch(int throwNum)
  49.         {
  50.             cout<<"Поймано исключение "<<throwNum<<endl;
  51.         }
  52.     }
  53.  
  54.     system("pause");
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement