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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:29:22+00:00 2026-05-27T21:29:22+00:00

VS2010 has supported the C++11 partially. I compile the code below in VS2010 RTM.

  • 0

VS2010 has supported the C++11 partially. I compile the code below in VS2010 RTM. I’m confused why the code CLS() is analyzed to different meanings. In the line “decltype(CLS()) obj1;”, the CLS() denotes an class object entity. But in the line “CLS obj2(CLS());”, the CLS() denotes a function pointer, which retuns a CLS object with no parameter. Is the behavior expected? Is it described in the standard?

struct CLS
{
    int mi;
};

int _tmain(int argc, _TCHAR* argv[])
{
    decltype(CLS()) obj1;
    obj1.mi = 10;

    CLS obj2(CLS());
    obj2.mi = 10; // error C2228: left of '.mi' must have class/struct/union

    return 0;
}

UPDATE 12/8/2011

Per C++11 7.1.6.2/1, the expected string in the parenthesis is an expression. The compiler just needs to check if the string can be parsed as a valid expression. If yes, the code is well-formed. So for the code “decltype(CLS()) obj1;”, the “CLS()” is treated as a valid expression which denotes a difinition of object.

decltype-specifier:
    decltype ( expression )

UPDATE 1/3/2012

Potatoswatter gives the explanation why “CLS obj2(CLS());” is a declaration other than an object definition.

Anything that may be interpreted as either an expression or a declaration is a declaration, however unusual it may be. CLS obj2( CLS() ); declares a function whose parameter type CLS() is a function with no arguments returning CLS, and whose return type is CLS.

  • 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-27T21:29:23+00:00Added an answer on May 27, 2026 at 9:29 pm

    As others have said, this is the Most Vexing Parse. Anything that may be interpreted as either an expression or a declaration is a declaration, however unusual it may be. CLS obj2( CLS() ); declares a function whose parameter type CLS() is a function with no arguments returning CLS, and whose return type is CLS.

    For example,

    CLS obj2( CLS() ); // forward declaration
    
    CLS obj2( CLS fun() ) { // definition
        return fun(); // use unusual functional argument
    }
    
    CLS foo() { // define a function to use as unusual argument
        return CLS();
    }
    
    int main() {
        CLS obj2( CLS() ); // still a forward declaration, even in this context!
    
        CLS x = obj2( foo );
    }
    

    The solution is to use C++11’s uniform initialization:

    CLS obj2{ CLS() };
    

    or simply

    CLS obj2{};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to this schema VS2010 Premium and Ultimate has a tool for checking Code
Not sure I heard this right, but VS2010 no longer has support for Wix?
I'm using MVC2 with VS2010 I have a view that has two partial views
I am not able to install VS2010 and WM7's SDK side by side. Has
Has the menu & toolbar customization functionality in VS2010 been reduced? I can't seem
I'm debugging my C++ Win32 program in VS2010 and I always get Windows has
I am building my first ASP.Net web application project in VS2010. The site has
While migrating some code to the latest version of F#, included in VS2010 b1,
Our code uses different settings for development and production environments so we were looking
I have an ASP.NET web application I'm running with VS2010 that has session timeout

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.