fork download
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <stdexcept>
  5.  
  6. template<class T>
  7. struct svector : private ::std::vector<T>
  8. {
  9. typedef ::std::vector<T>
  10. parent;
  11.  
  12. using parent::parent;
  13.  
  14. T& operator[](const size_t n)
  15. {
  16. return this->at(n);
  17. }
  18. const T& operator[](const size_t n)const
  19. {
  20. return this->at(n);
  21. }
  22.  
  23. };
  24.  
  25. int main()
  26. {
  27. std::cout << "Hello, world!\n";
  28.  
  29. const int ar[]={1,2,3};
  30. svector<int> example(ar, ar+3);
  31.  
  32. try{
  33. example[10];
  34. }
  35. catch(const std::out_of_range& e)
  36. {
  37. std::cout<<"OUT OF RANGE: " << e.what()<<'\n';
  38. }
  39.  
  40. catch(const std::exception& e)
  41. {
  42. std::cout<<e.what()<<'\n';
  43. }
  44.  
  45.  
  46. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
Hello, world!
OUT OF RANGE: vector::_M_range_check: __n (which is 10) >= this->size() (which is 3)