1

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> bubuInstance;
vector<SomeClassType>::iterator it = bubuInstance.Foo();

What's wrong? How do I fix it?


Community
  • 1
  • 1
cantrem
  • 616
  • 2
  • 8
  • 20
  • What? That's not a duplicate at all. Just because it's talking about the same thing doesn't inherently make it a duplicate. The OP didn't even know what `typename` _is_, let alone know to ask how to use it. – Lightness Races in Orbit Jun 01 '11 at 09:15

2 Answers2

2

Search for "dependent names" on google.

Anyway to fix it use typename :

template<typename TypeName> class Bubu
{
   ...
   typename vector<TypeName>::iterator Foo()
   {
      ...
   }
   ...
}
BЈовић
  • 62,405
  • 41
  • 173
  • 273
1

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()
    {
    }
};
Blazes
  • 4,721
  • 2
  • 22
  • 29