'Invalid use of template-name 'std::iterator' without an argument list'

Hello. I am receiving an error about the way I prepare my function. Can anyone explain to me the correct syntax? Thanks. The error is at line 86.

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <string>

using namespace std;

template<class T>
class ring
{
private:
	int size;
	int pos;
	T *value;
public:
	class iterator;
	ring(int);
	~ring();
	iterator begin() { return iterator(0, *this); }
	iterator end() { return iterator(size, *this); }
	void add(T);
	T &get(int position) { return value[position]; }
};

template<class T>
class ring<T>::iterator
{
private:
	int m_pos;
	ring &m_ring;
public:
	iterator(int, ring &);
	~iterator();
	iterator &operator++(int);
};

int main()
{
	
	
	

	cin.get();
	return 0;
}

template<class T>
ring<T>::ring(int size)
{
	this->size = size;
	value = new T[size];
}

template<class T>
ring<T>::~ring()
{
	delete[]value;
}

template<class T>
void ring<T>::add(T worth)
{
	value[pos++] = worth;
	
	if (pos == size)
	{
		pos = 0;
	}
}

////// iterator class ///////

template<class T>
ring<T>::iterator::iterator(int m_pos, ring &m_ring)
{
	this->m_pos = m_pos;
	this->m_ring = m_ring;
}

template<class T>
ring<T>::iterator::~iterator()
{
}

template<class T>

// I don't know how to declare the iterator
iterator ring<T>::iterator::operator++(int)
{
	m_pos++;

	return *this;
}
Last edited on
Change line 86 to
typename ring<T>::iterator& ring<T>::iterator::operator++(int)

You would most likely find it easiest to implement the member functions of class templates inside the body of the class definition.
Topic archived. No new replies allowed.