C++ templates inside templates [duplicate]
Possible Duplicate:
Where and why do I have to put “template” and “typename” on dependent names?
Here's my problem:
template<typename TypeName> class Bubu
{
...
vector<TypeName>::iterator Foo()
{
...
}
...
}
This gives:
error C2146: syntax error: missing ';' before identifier 'Foo'
If I change the typename to an actual type, like int or SomeClass, it works:
vector<int>::iterator Foo(){}
What I want to have is something like:
Bubu<SomeClassType> b开发者_JAVA技巧ubuInstance;
vector<SomeClassType>::iterator it = bubuInstance.Foo();
What's wrong? How do I fix it?
Search for "dependent names" on google.
Anyway to fix it use typename :
template<typename TypeName> class Bubu
{
...
typename vector<TypeName>::iterator Foo()
{
...
}
...
}
You need to prefix 'typename', and also finish-off your class with a semi-colon ';'
template<typename TypeName>
class Bubu
{
typename vector<typename TypeName>::iterator Foo()
{
}
};
精彩评论