I have a simple piece of code that is giving me a compiler error. I've had no issues compiling and running this in a windows environment under Visual Studio, but now under linux, using gcc, I am having problems. Note I am using gcc 4.4.5, and using the -std=c++0x directive.
This code snippet is in a header file, file_handling.h, which does include all the necessary libraries (vector, string, fstream, etc). The variable 'output_file' is a member of the LogFile object, and gets properly checked/instantiated/etc elsewhere. The code itself is trivially simple, which is why I am stumped:
template <typename T> void LogFile::put(std::string const & header, std::vector<T> const & data) {
output_file << header << " " << std::scientific << data[0] << std::endl;
for (std::vector<T>::const_iterator value = (data.begin()+1); value < data.end(); ++value) {
output_file << *value << std::endl;
}
}
The compiler states:
In file included from file_handling.cpp:2:
file_handling.h: In member function 'void LogFile::put(const std::string&, const std::vector<T, std::allocator<_Tp1> >&)':
file_handling.h:132: error: expected ';' before 'value'
file_handling.h:132: error: 'value' was not declared in this scope
make: *** [file_handling.o] Error 1
Why does gcc not see the in-situ declaration of 'value' as a const_iterator? I've tried the following as a sanity check:
template <typename T> void LogFile::put(std::string const & header, std::vector<T> const & data) {
std::vector<T>::const_iterator value;
output_file << header << " " << std::scientific << data[0] << std::endl;
for (value = (data.begin()+1); value < data.end(); ++value) {
output_file << *value << std::endl;
}
}
And receive the exact same compiler report. Given this looks simple, and worked fine in Visual Studio, what am I missing or misunderstanding about gcc and/or a Linux environment?