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

  • Home
  • SEARCH
  • 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 7762049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:17:33+00:00 2026-06-01T14:17:33+00:00

While trying to answer this question I found without () (which invokes C++ most

  • 0

While trying to answer this question I found without () (which invokes “C++ most vexing parse”) the output of g++ is 1 (Can be seen here: http://ideone.com/GPBHy), where as visual studio gives a linker error. I couldn’t understand how the output can 1, any clues?

  • 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-06-01T14:17:35+00:00Added an answer on June 1, 2026 at 2:17 pm

    As the answers to the question already explain, due to the “Most Vexing Parse” the statement instead of defining an object named str with the two istream_iterators to specify its initializers, is parsed as a declaration of a function named str that returns a string.

    So a simple version of the program resolves to, this online sample:

    #include<iostream>  
    
    void doSomething()
    {
    } 
    void (*ptr)()=&doSomething;
    
    int main()
    {
    
        std::cout << ptr << "\n"; 
        std::cout << doSomething;
        return 0;
    }
    

    Output:

    1
    1
    

    Note that there is no overloaded operator << that takes an std::ostream and a function pointer as arguments, this is because there can be any number of user defined function types and ofcourse a standard overloaded api cannot account for them all.

    Given that the compiler tries to find the best match among the existing overloads which happens to be bool (a function pointer is implicitly convertible to bool[#1]).
    In particular,

    basic_ostream& operator<< (bool& val );
    

    Since the function pointer points to something and not null, the value is printed as 1.


    [#1]C++03 4.12 Boolean conversions

    1 An rvalue of arithmetic, enumeration, pointer, or pointer to member type can be converted to an rvalue of type bool.

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

Sidebar

Related Questions

While trying to answer this question I found that the code int* p =
This question is a result of what i noticed while trying to answer another
While trying to answer a question in the vicinity ' Unit Testing WPF Bindings
Sorry answer found while typing I am trying to connect to an external webservice
When trying to answer this question : Leave off underscore in function literal I
I haven't found an answer to this particular question; perhaps there isn't one. But
While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
Update: A sample project reproducing this bug can be found here at Microsoft Connect
I have a question about Clozure CL. While I was trying to quickload a
While trying to move an axis2 web-app from glassfish3 to tomcat6, I can't seem

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.