cpp:exception
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cpp:exception [2023/05/15 13:57] – gthanos | cpp:exception [2023/05/15 14:01] (current) – gthanos | ||
---|---|---|---|
Line 11: | Line 11: | ||
class Vector { | class Vector { | ||
int *array; | int *array; | ||
- | | + | |
| | ||
public: | public: | ||
- | Vector(int length=0); | + | Vector(long length=0); |
~Vector(); | ~Vector(); | ||
int & | int & | ||
Line 22: | Line 22: | ||
<code cpp Vector.cpp> | <code cpp Vector.cpp> | ||
#include " | #include " | ||
- | Vector:: | + | Vector:: |
size = length; | size = length; | ||
array = new (nothrow) int[size]; | array = new (nothrow) int[size]; | ||
Line 52: | Line 52: | ||
int main() { | int main() { | ||
- | | + | |
cout << "Enter verctor size: "; | cout << "Enter verctor size: "; | ||
cin >> size; | cin >> size; | ||
Line 71: | Line 71: | ||
class Vector { | class Vector { | ||
int *array; | int *array; | ||
- | | + | |
| | ||
public: | public: | ||
- | Vector(int length=0); | + | Vector(long length=0); |
~Vector(); | ~Vector(); | ||
int & | int & | ||
Line 84: | Line 84: | ||
#include " | #include " | ||
- | Vector:: | + | Vector:: |
size = length; | size = length; | ||
array = new int[size]; | array = new int[size]; | ||
Line 108: | Line 108: | ||
int main() { | int main() { | ||
- | | + | |
- | | + | |
- | cout << "Enter verctor size: "; | + | cout << "Enter verctor size: "; |
- | cin >> size; | + | cin >> size; |
- | try { | + | try { |
- | Vector v(size); | + | Vector v(size); |
- | } catch(std:: | + | } catch(std:: |
- | | + | std::cout << "Allocation failure!\n"; |
- | | + | exit(-1); |
- | | + | } |
- | } | + | |
- | | + | |
- | } | + | |
- | | + | |
- | v.valueAt(i) = 100-1; | + | |
- | } while(size< | + | |
} | } | ||
</ | </ |
cpp/exception.1684159030.txt.gz · Last modified: 2023/05/15 13:57 by gthanos