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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:53:36+00:00 2026-05-13T17:53:36+00:00

Observation: the codes pasted below were tested only with GCC 4.4.1, and I’m only

  • 0

Observation: the codes pasted below were tested only with GCC 4.4.1, and I'm only interested in them working with GCC.

Hello,

It wasn’t for just a few times that I stumbled into an object construction statement that I didn’t understand, and it was only today that I noticed what ambiguity was being introduced by it. I’ll explain how to reproduce it and would like to know if there’s a way to fix it (C++0x allowed). Here it goes.

Suppose there is a class whose constructor takes only one argument, and this one argument’s type is another class with a default constructor. E.g.:

struct ArgType {};

class Class
{
public:
    Class(ArgType arg);
};

If I try to construct an object of type Class on the stack, I get an ambiguity:

Class c(ArgType()); // is this an object construction or a forward declaration
                    // of a function "c" returning `Class` and taking a pointer
                    // to a function returning `ArgType` and taking no arguments
                    // as argument? (oh yeh, loli haets awkward syntax in teh
                    // saucecode)

I say it’s an object construction, but the compiler insists it’s a forward declaration inside the function body. For you who still doesn’t get it, here is a fully working example:

#include <iostream>

struct ArgType {};
struct Class {};

ArgType func()
{
    std::cout << "func()\n";
    return ArgType();
}

int main()
{
    Class c(ArgType());

    c(func); // prints "func()\n"
}

Class c(ArgType funcPtr()) // Class c(ArgType (*funcPtr)()) also works
{
    funcPtr();
    return Class();
}

So well, enough examples. Anyone can help me get around this without making anything too anti-idiomatic (I’m a library developer, and people like idiomatic libraries)?

— edit

Never mind. This is a dupe of Most vexing parse: why doesn't A a(()); work?.

Thanks, sbi.

  • 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-13T17:53:36+00:00Added an answer on May 13, 2026 at 5:53 pm

    This is known as “C++’s most vexing parse”. See here and here.

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

Sidebar

Related Questions

Not so much a question as an observation... I'm just upgrading to SQL Server
Are these nested comments allowed in a XML file? <!-- Making only one observation
I have missing values for a lot of cases and the code below only
I'm working with emergency room ICD-9 code data (health diagnoses), which are three-digit codes
hello all i am new to iphone development i am working on a application
This is more an observation than a real question: MS-Access (and VBA in general)
A few interesting observations w.r.t equals operator on 0 and 0.0 new Double(0.0).equals(0) returns
I am trying to validate a few XML files and I'm failing due to
I have the following matching problem: I have two data.frames, one with an observation
This is part observation, part question. First the observation: While everyone talks of modular

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.