When trying to compile the following C ++ code snippet (full source code below)
A::A(istream& i) { vector<string> words( istream_iterator<int>(i), istream_iterator<int> ); words.begin(); }
I get an error
istream_it.cpp:12: error: request for member 'begin' in 'words', which is of non-class type 'std::vector<int, std::allocator<int> >( std::istream_iterator<int, char, std::char_traits<char>, long int>, std::istream_iterator<int, char, std::char_traits<char>, long int>)'
I know that this error is usually caused by a random declaration of a function using the no-parameters operator, as in
string s(); s.size();
but in this case, I already deleted all the unnecessary code and still can not understand what exactly is happening, or what will be the correct syntax.
Full source:
#include <sstream> #include <vector> #include <iterator> #include <string> using namespace std; class A { public: A(istream& i) { vector<int> words(istream_iterator<int>(i), istream_iterator<int> ); words.begin(); } }; int main(int argc, char** argv) { istringstream iss("1 2 3"); A a(iss); return 0; }
Benno source share