template keyword needed

Joined
Feb 12, 2008
Messages
108
Reaction score
0
Hello everyone,


In the Bjarne's book, there is a line of code like this,

Code:
typedef typename A::template rebind <Link>::other Link_alloc;

It means if A is allocator, we can use use to allocate arbitrary type of object instance, said by Bjarne.

I understand this statement, my question is about the grammar. Do we need the template keyword? Why?

I have tested without temlpate keyword, the code still works. Any ideas?

Code:
template <class T1> class  Foo {
public:
	template <class T2> class Goo {
	public:
		typedef T2	GooValueType;
	};
};

int main()
{
	Foo <int>::Goo<char>::GooValueType a1;
	Foo <int>::template Goo<char>::GooValueType a2;
	return 0;
}


thanks in advance,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top