-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric_vector_pg_379.cpp
65 lines (49 loc) · 961 Bytes
/
generic_vector_pg_379.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
using namespace std;
template<class T>
class vector
{
private:
int size;
T *val;
public:
vector(int vl):size(vl) {val=new T[vl];}
~vector() {delete []val;}
T& modify(int ele)
{
return val[ele];
}
vector & operator *(double mul)
{
for (int i = 0; i < size; i++)
{
val[i]=mul*val[i];
}
return *this;
}
template<class O>
friend ostream & operator << (ostream & out, vector<O> & obj);
};
template<class T>
ostream & operator << (ostream & out, vector<T> & obj)
{
out<<"( ";
for (int i = 0; i < obj.size; i++)
{
out<<obj.val[i];
if (i!=obj.size-1)
{
cout<<", ";
}
}
out<<" )"<<endl;
return (out);
}
int main()
{
vector <int> v1(3);
v1.modify(0) = 12;
v1*3;
cout<<v1;
return 0;
}