typename?

Hi, I'm currently following Accelerated C++ and I have this code

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
  #include "stdafx.h"
#include <Windows.h>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

template<class T>
T median(vector<T> v)
{
	typedef typename vector<T>::size_type vec_sz;
	vec_sz size = v.size();
	if (size == 0)
		throw ("median of an empty vector");
	sort(v.begin(), v.end());
	vec_sz mid = size / 2;
	return size % 2 == 0 ? (v[mid] + v[mid - 1])/2 : v[mid];
}

int _tmain(int argc, _TCHAR* argv[])
{
	vector<int> vi;
	vi.push_back(1);
	vi.push_back(3);

	cout << "med: " << median(vi) << endl;

	system("PAUSE");
	return 0;
}


However I can do that
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
  #include "stdafx.h"
#include <Windows.h>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

template<class T>
T median(vector<T> v)
{
	typedef vector<T>::size_type vec_sz;
	vec_sz size = v.size();
	if (size == 0)
		throw ("median of an empty vector");
	sort(v.begin(), v.end());
	vec_sz mid = size / 2;
	return size % 2 == 0 ? (v[mid] + v[mid - 1])/2 : v[mid];
}

int _tmain(int argc, _TCHAR* argv[])
{
	vector<int> vi;
	vi.push_back(1);
	vi.push_back(3);

	cout << "med: " << median(vi) << endl;

	system("PAUSE");
	return 0;
}


and it does exactly the same. What is the purpose of typename if it does nothing?
If this works for you then it must be your compiler that has this "feature". In standard C++ you need typename.
Ok thank you
Topic archived. No new replies allowed.