simple problem with template function.

Hi all,

My code was very fine until I added a function to a template:

/// Format a string with all names of the factory
template <class T> std::string getAllNamesInFactory(const std::string & separator, const std::string & surround)
{
const std::vector<T*> & v = T::getAllInstances() ; // exists.
line 126: std::vector<T*>::const_iterator it ; //=v.begin();
std::ostringstream os ;
/* some stuff done to the stream ... */
return os.str() ;
}


I have the following message from the compiler:
g++ -c -O2 -I.. -fPIC -o build/Release/GNU-Linux-x86/src/strategy/indicator/indicator.o src/strategy/indicator/indicator.cpp
../tinsim/src/patterns/factory.h: In function ‘std::string tinsim::getAllNamesInFactory(const std::string&, const std::string&)’:
../tinsim/src/patterns/factory.h:126: error: expected `;' before ‘it’

What is wrong line 126 ???

The same code without line 126 compiles ok.

Thanks for your help,

Regards,
I have my awser :

line 126 should be :
typename std::vector<T*>::const_iterator it ;

instead of:
std::vector<T*>::const_iterator it ;
Yep, was just going to say that, here is quite a good explanation as to why if you're not sure

http://www.cplusplus.com/forum/general/1468/
Topic archived. No new replies allowed.