#include #include #include #define MAX_VAL 750 int main(int, char**) { Array numbers(MAX_VAL); int* mirror = new int[MAX_VAL]; srand(time(NULL)); for (int i = 0; i < MAX_VAL; i++) { const int value = rand() % 100; numbers[i] = value; mirror[i] = value; } //SCOPE { Array tmp = numbers; const Array test(tmp); std::cout << "accessing a const value : " << (int) test[15] << std::endl; } std::cout << "checking if values are the same after a copy..." << std::endl; for (int i = 0; i < MAX_VAL; i++) { if (mirror[i] != numbers[i]) { std::cerr << "didn't save the same value!!" << std::endl; return 1; } } std::cout << "the values are the same ! :D" << std::endl << std::endl; std::cout << "trying -2:" << std::endl; try { numbers[-2] = 0; } catch(const std::exception& e) { std::cerr << e.what() << '\n'; } std::cout << std::endl << "trying a correct value (15):" << std::endl; try { std::cout << numbers[15] << std::endl; numbers[15] = 0; std::cout << numbers[15] << std::endl; } catch(const std::exception& e) { std::cerr << e.what() << '\n'; } std::cout << std::endl << "trying MAX_VAL:" << std::endl; try { numbers[MAX_VAL] = 0; } catch(const std::exception& e) { std::cerr << e.what() << '\n'; } std::cout << std::endl; for (int i = 0; i < MAX_VAL; i++) { std::cout << numbers[i] << " "; } std::cout << std::endl; delete [] mirror; return 0; }