Guest User

Untitled

a guest
Jul 21st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <locale.h>
  4.  
  5. class vec
  6. {
  7. private:
  8. int _size;
  9. int * _error;
  10. unsigned long ** _elements;
  11. void init();
  12. void exception(int code);
  13. protected:
  14. public:
  15. vec();
  16. vec(int size);
  17. vec(int size, int &error);
  18. int error();
  19. void test();
  20. };
  21.  
  22. void vec::init()
  23. {
  24. _elements = new unsigned long * [_size];
  25.  
  26. for(int i = 0; i < _size; i++)
  27. {
  28. _elements[i] = new unsigned long;
  29. }
  30. }
  31.  
  32. vec::vec()
  33. {
  34. _size = 1;
  35.  
  36. init();
  37. }
  38.  
  39. vec::vec(int size)
  40. {
  41. _size = size;
  42.  
  43. init();
  44. }
  45.  
  46. vec::vec(int size, int &error)
  47. {
  48. _size = size;
  49. _error = &error;
  50. }
  51.  
  52. /* порождает заполнение перменной ошибки */
  53. void vec::exception(int code)
  54. {
  55. *_error = code;
  56. }
  57.  
  58. /* получение кода ошибки */
  59. int vec::error()
  60. {
  61. return * _error;
  62. }
  63.  
  64. void vec::test()
  65. {
  66. exception(123);
  67. }
  68.  
  69. int main(int argc, char * argv[])
  70. {
  71. int error;
  72.  
  73. setlocale(LC_ALL, "rus");
  74.  
  75. /* тестируем класс */
  76. vec v = vec(1, error);
  77.  
  78. v.test();
  79.  
  80. std::cout << "Можно получить ошибку через переменную, которую задали в конструкторе: " << error << std::endl;
  81. std::cout << "А можно и отдельно: " << v.error() << std::endl;
  82.  
  83. _getch();
  84.  
  85. return 0;
  86. }
Add Comment
Please, Sign In to add comment