Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4996)
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- using namespace std;
- #define MAX 2435
- template <class T>
- class Vector {
- private:
- T elem[MAX];
- int n;
- public:
- Vector(int n);
- int getNrElemente() const;
- T& operator[] (int i);
- int & operator +(int i) {
- int suma = 0;
- this->elem[0] += i;
- return this->elem[0];
- }
- void print();
- };
- template <class T>
- Vector<T>::Vector<T>(int n) {
- this->n = n;
- if (n>MAX)
- throw out_of_range("Depasire dimensiune maxima");
- else {
- for (int i = 0; i < n; i++) {
- this->elem[i] = 0;
- }
- }
- }
- template <class T>
- int Vector<T>::getNrElemente() const {
- return n;
- }
- template <class T>
- T& Vector<T>:: operator[] (int i) {
- if (i >= 0 && i < n) {
- return elem[i];
- }
- else {
- throw out_of_range("Depasire limite");
- }
- }
- template <class T>
- void Vector<T>::print() {
- int i;
- for (i = 0; i < n; i++) {
- cout << elem[i] << " ";
- }
- cout << endl;
- }
- void main() {
- Vector<int> frentzy(2);
- frentzy.print();
- int cacat = frentzy + 3;
- frentzy.print();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement