Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7091299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:10:04+00:00 2026-05-28T08:10:04+00:00

Consider this example: #include <iostream> #include <string> #include <vector> #include <iterator> int main() {

  • 0

Consider this example:

#include <iostream>
#include <string>
#include <vector>
#include <iterator>

int main()
{
    std::string sen = "abc def ghi jkl";
    std::istringstream iss(sen);

    std::vector<std::string>    // declaration in question
    vec(std::istream_iterator<std::string>(iss),
        std::istream_iterator<std::string>());

    std::copy(vec.begin(), vec.end(),
              std::ostream_iterator<std::string>(std::cout, "\n"));
}

The compiler throws an error at the call to std::copy

request for member 'begin' in 'vec', which is of non-class type...

I can get around the error like this:

std::istream_iterator<std::string> it_begin(iss);
std::istream_iterator<std::string> it_end;
std::vector<std::string> vec(it_begin, it_end);

or by putting parentheses around each parameter, like this:

std::vector<std::string>
vec((std::istream_iterator<std::string>(iss)),
    (std::istream_iterator<std::string>()));

or even with the new uniform initialization in C++11:

std::vector<std::string> vec { /*begin*/, /*end*/ };

Why is compiler parsing the declaration in the example as a function declaration? I know about most vexing parse, but I thought that only happens with empty parameter lists.
I also wonder why the second workaround works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:10:05+00:00Added an answer on May 28, 2026 at 8:10 am

    It’s still the most vexing parse.

    std::vector<std::string>                     // return type
    vec(                                         // function name
        std::istream_iterator<std::string>(iss), // param 1: an iterator called (iss), or just iss
        std::istream_iterator<std::string>()     // param 2: unnamed function 
    );                                           //          returning iterator
    

    geordi says:

    <tomalak> << ETYPE_DESC(vec); std::vector<std::string> vec(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>());
    <geordi> lvalue function taking a istream_iterator<string, char, char_traits<char>, long> , a pointer to a nullary function returning a istream_iterator<string, char, char_traits<char>, long> , and returning a vector of strings
    

    The crux of it, really, is that your parameter names can have parentheses around them (i.e. iss → (iss)) without altering the semantics of the declaration. Sometimes.

    Use another set of parentheses that also surround the type, as you showed, to force that first parameter (and, consequently, the second) to be parsed as an expression rather than a declaration.


    If it helps, also consider:

    void foo(int (x)) {
       cout << x;
    }
    
    int main() {
       foo(42);
    }
    

    Output is 42.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this example: #include <algorithm> #include <iostream> int main() { std::string str = abcde4fghijk4l5mnopqrs6t8uvwxyz;
Consider this example: #include <iostream> class myclass { public: void print() { std::cout <<
Consider following example. #include <iostream> #include <algorithm> #include <vector> #include <boost/bind.hpp> void func(int e,
Consider this code: #include <vector> void Example() { std::vector<TCHAR*> list; TCHAR* pLine = new
Consider next example : #include <iostream> template< int a > void foo(); int main(int
Let us consider the following factorial example : #include <iostream.h> int factorial(int); void main(void)
Consider this simplified example: #include <list> typedef std::list<int> IntList; class KindaIntList { public: IntList::const_iterator
Consider the following example: #include <iostream> #include <sstream> #include <vector> #include <wchar.h> #include <stdlib.h>
consider this simple and pointless code. #include <iostream> struct A { template<int N> void
Consider following example. #include <iostream> #include <boost/optional.hpp> template < typename A > int boo(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.