File tree 1 file changed +62
-0
lines changed 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ template <typename T>
2
+ class Iterator
3
+ {
4
+ public:
5
+ virtual void first () = 0;
6
+ virtual void next () = 0;
7
+ virtual bool isDone () const = 0;
8
+ virtual T& current () = 0;
9
+ };
10
+
11
+
12
+
13
+ template <typename T>
14
+ class MyCollection {
15
+
16
+ public:
17
+
18
+ Iterator<T> GetIterator (){
19
+ // ...
20
+ }
21
+
22
+ };
23
+
24
+ template <typename T>
25
+ class CollectionIterator : public Iterator <T>{
26
+ MyCollection<T> mc;
27
+ public:
28
+
29
+ CollectionIterator (const MyCollection<T> & c): mc(c){ }
30
+
31
+ void first () override {
32
+
33
+ }
34
+ void next () override {
35
+
36
+ }
37
+ bool isDone () const override {
38
+
39
+ }
40
+ T& current () override {
41
+
42
+ }
43
+ };
44
+
45
+ void MyAlgorithm ()
46
+ {
47
+ MyCollection<int > mc;
48
+
49
+ Iterator<int > iter= mc.GetIterator ();
50
+
51
+ for (iter.first (); !iter.isDone (); iter.next ()){
52
+ cout << iter.current () << endl;
53
+ }
54
+
55
+ }
56
+
57
+
58
+
59
+
60
+
61
+
62
+
You can’t perform that action at this time.
0 commit comments