Bizarre C++ compiler problem
- by Yassin
Hi, I have the following C++ code:
typedef istream_iterator<string> isi;
// (1)
vector<string> lineas(isi(cin), isi());
// (2)
//vector<string> lineas;
//copy(isi(cin), isi(), back_inserter(lineas));
typedef vector<string>::iterator vci;
for (vci it = lineas.begin(); it != lineas.end(); ++it)
cout << *it << endl;
However, I get the error while compiling:
test.cpp: In function 'int main(int, char**)':
test.cpp:16: error: request for member 'begin' in 'lineas', which is of non-class type 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(main(int, char**)::isi, main(int, char**)::isi (*)())'
test.cpp:16: error: request for member 'end' in 'lineas', which is of non-class type 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(main(int, char**)::isi, main(int, char**)::isi (*)())'
However, if I replace (1) by (2), it compiles.
I'm using g++ 4.4.0
What's wrong?