Advertisement
naskedvi

S6 - zad.8

Apr 29th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <new>
  3. #include <iomanip>
  4.  
  5.  
  6. template<typename Tip>
  7. void KreirajMatricu(Tip **&mat, int n)
  8. {
  9. try {
  10. Tip **mat(new Tip*[n]);
  11. for(int i=0; i<n; i++)
  12. mat[i]=nullptr;
  13. try{
  14. for(int i=0; i<n; i++)
  15. mat[i]= new Tip[n];
  16. }
  17. catch(...) {
  18. for(int i=0; i<n; i++)
  19. delete[] mat[i]
  20. delete[] mat;
  21. throw;
  22. }
  23. }
  24. catch(...) {
  25. throw "Alokacija nije uspjela!\n";
  26. }
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32. double **m(0);
  33. try {
  34. KreirajMatricu(m, 10)
  35. }
  36. catch(const char poruka[]) {
  37. std::cout << poruka;
  38. }
  39.  
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement