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 6233435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:18:00+00:00 2026-05-24T10:18:00+00:00

What is the difference between the code snippets labeled version 1 and version 2

  • 0

What is the difference between the code snippets labeled “version 1” and “version 2” in the following code section:

int main() {
  using namespace std;
  typedef istream_iterator<int> input;

  // version 1)
  //vector<int> v(input(cin), input());

  // version 2)
  input endofinput;
  vector<int> v(input(cin), endofinput);
}

As far as I understand “version 1” is treated as function declaration. But I don’t understand why nor what the arguments of the resulting function v with return type vector<int> are.

  • 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-24T10:18:01+00:00Added an answer on May 24, 2026 at 10:18 am

    why

    Because the Standard says, more or less, that anything that can possibly be interpreted as a function declaration will be, in any context, no matter what.

    what the arguments… are

    You might not believe this, but it’s true. input(cin) is treated as input cin; in this spot, parentheses are allowed and simply meaningless. However, input() is not treated as declaring a parameter of type input with no name; instead, it is a parameter of type input(*)(), i.e. a pointer to a function taking no arguments and returning an input. The (*) part is unnecessary in declaring the type, apparently. I guess for the same reason that the & is optional when you use a function name to initialize the function pointer…

    Another way to get around this, taking advantage of the fact that we’re declaring the values separately anyway to justify skipping the typedef:

    istream_iterator<int> start(cin), end;
    vector<int> v(start, end);
    

    Another way is to add parentheses in a way that isn’t allowed for function declarations:

    vector<int> v((input(cin)), input());
    

    For more information, Google “c++ most vexing parse”.

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

Sidebar

Related Questions

What is the difference between the following two snippets of code: using (Object o
Is there any practical difference between the following two code snippets: NSObject * obj
can somebody please tell me the difference between the following two code snippets: //Code
I am using the following code snippet to find difference between two dates and
What is the difference between the below code snippets? Won't both be using threadpool
Is there any differences between following code snippets? I'm using VS 2010, .NET 4,
What's the difference between the two code below. int a[] = {0,0}; int a[2]
I have been told that there is a performance difference between the following code
What is the difference between these code snippets? 1) $f = 12.044545; printf(%f,$f); vprintf(%f,$f);
What is the difference between these two code snippets? open (MYFILE, '>>data.txt'); open (MYFILE,

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.