I have the following code:
template <typename Provider>
inline void use()
{
typedef Provider::Data<int> D;
}
Where I’m basically trying to use a template class member ‘Data’ of some ‘Provider’ class, applied to ‘int’, but I get the following errors:
util.cpp:5: error: expected init-declarator before '<' token
util.cpp:5: error: expected `,' or `;' before '<' token
I’m using GCC 4.3.3 on a Solaris System.
The problem is that, when the compilers parses
use()for the first time, it doesn’t knowProvider, so it doesn’t know whatProvider::Datarefers to. It could be a static data member, the name of a member function or something else. That’s why you have to put thetypenamein.The additional
templateis necessary whenever the nested name is the name of a template. If it was something else, thenData < ...could be a comparison.