error "missing 'typename' prior to dependent type name 'vector<T, A>::iterator'"

It's giving me the error mentioned in the title on this code in the custom vector from the book PPP2:
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
template<typename T, typename A>
vector<T, A>::iterator vector<T, A>::insert(vector<T, A>::iterator p, const T &val)
{
	int index = p - begin();
	if (size() == capacity())
	{
		reserve(size() == 0 ? 8 : 2 * size());		// make sure we have space
	}

	// first copy last element into uninitialized space
	alloc.construct(elem + sz, *back());

	++sz;
	iterator pp = begin() + index;		// the place to put val
	for (auto pos = end() - 1; pos != pp; --pos)
	{
		*pos = *(pos - 1);		// copy elements one position to the right
	}
	*(begin() + index) = val;		// "insert" val
	return pp;
}

template<typename T, typename A>
vector<T, A>::iterator vector<T, A>::erase(vector<T, A>::iterator p)
{
	if (p == end())
	{
		return p;
	}
	for (auto pos = p + 1; pos != end(); ++pos)
	{
		*(pos - 1) = *pos;		// copyy element "one position to the left"
	}
	alloc.destroy(&*(end() - 1));		// destroy surplus copy of last element
	--sz;
	return p;
}


I've clearly done what it's asking, so why is it saying that?

If anyone wants to look at it in the context of the full header file (it's a header file I wrote), please let me know and I'll show it.
Solved by doing this:
1
2
template<typename T, typename A>
typename vector<T, A>::iterator vector<T, A>::insert(vector<T, A>::iterator p, const T &val)
for insert() and erase().

So is it because the compiler needs to tell for sure that it's a typename alias for a vector::T* and not a greater-than or less-than comparison? Is that the reason for this?

Anyway, yeah, thanks.
Has the "Down with the typename!" proposal already been accepted in C++17? Or is it still just a proposal?
No - and it won't be - we'll have to wait. C++17 is feature-complete and has been for a few months.

FYI, the paper is numbered p0634r1.
Last edited on
Ah, so the proposal was made after the standard became feature-complete (or maybe just at such a time that it couldn't make it into the standard in time)?

Anyway, the initial problem has already been solved, so I'll mark it as such.
Topic archived. No new replies allowed.