-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
44 lines (36 loc) · 769 Bytes
/
template.cpp
File metadata and controls
44 lines (36 loc) · 769 Bytes
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
#include <iostream>
using namespace std;
template <class T> class Array {
private:
T* pointer;
int size;
int multiplier;
public:
Array(T arr[], int s);
void print();
};
template <typename T> Array<T>::Array(T arr[], int s){
pointer = new T[s];
size = s;
multiplier = 2;
for(int i=0; i < size; i++){
pointer[i] = arr[i] * multiplier;
}
}
template <typename T> void Array<T>::print(){
for(int i=0; i < size; i++){
if (i == 0){
cout << " " << *(pointer + i);
}
else{
cout << " - " << *(pointer + i);
}
}
cout << endl;
}
int main(){
int arr[6] = {2,3,4,5,2,3};
Array<int> a(arr, 5);
a.print();
return 0;
}