Just ran into weird problem with templates while porting code from Windows to Linux.
Provided sample compiles with MSVC and works flawlessly.
Code sample:
#include <vector>
#include <iostream>
typedef std::vector<int> IntArray;
template <typename TArray>
void printArray(TArray a)
{
typedef TArray::iterator iter;
for (iter it = a.begin(); it != a.end(); ++it)
std::cout << *it << std::endl;
}
int main()
{
IntArray a;
a.push_back(1);
a.push_back(2);
a.push_back(3);
printArray(a);
return 0;
}
But g++ complains that
In function ‘void printArray(TArray)’:
bar.cpp:9: error: expected initializer before ‘iter’
bar.cpp:10: error: ‘iter’ was not declared in this scope
bar.cpp:10: error: expected ‘;’ before ‘it’
bar.cpp:10: error: ‘it’ was not declared in this scope
After an hour of asking Google I have no idea what's going on.