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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:39:17+00:00 2026-06-05T04:39:17+00:00

Possible Duplicate: decltype and parenthesis int i=6; decltype((i)) var5 = i; // int& i

  • 0

Possible Duplicate:
decltype and parenthesis

int i=6;
decltype((i)) var5 = i;      // int& 

i just didn’t understand why ‘i’ which is in parentheses is regarded as Lvalue, now, i knew the application of the parentheses until i found that in MSDN:The inner parentheses cause the statement to be evaluated as an expression instead of a member access.(http://msdn.microsoft.com/en-us/library/dd537655.aspx), and i also didn’t understand a question i didn’t comprehend for a long time.

template<typename T>
class B
{
public:
    B(T t){printf("B\n");}

};
template <typename T >
void ft(T t)
{
    t.f();
}
int _tmain(int argc, _TCHAR* argv[])
{
    B<A> b1(A());   //one function declaration, A() is regarded as fun-ptr, and b1 is a function
    B<A> b2((A())); //A() is regarded as anonymous object.
    return 0;   
}

Why A() is regarded as anonymous object when put it in parentheses as (A()). the inner parentheses explanation about decltype in MSDN can’t apply to this situation. could someone tell me that is there a expanation about the parentheses function in this two situation in C++ standard. How should i understand this better, appreciate it very much!

  • 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-05T04:39:18+00:00Added an answer on June 5, 2026 at 4:39 am

    Those are really completely different situations.

    B<A> b1(A());
    

    This is a function declaration because it follows the syntax production “return-type identifier ‘(‘ parameter-declaration-list ‘)'”, where parameter-declaration-list is a comma-separated list of parameter-declarations. The production for such a declaration is “type abstract-declarator[opt]”. An abstract-declarator can, among other things, be empty, or “‘(‘ abstract-declarator ‘)'”. So “A()” matches a type (A) followed by the parentheses form of abstract-declarator containing the empty form of abstract-declarator. Thus, the code is syntactically a valid function declaration and is parsed as such.

    B<A> b1((A()));
    

    Here, if we want to go the function declaration route, we need to match “(A())” to parameter-declaration; however, there is no way to do this. So this isn’t a function declaration, and therefore must be a variable declaration with a direct-initializer.

    The other situation is grammatically unambiguous. Both decltype(i) and decltype((i)) are simple decltype derivations. In the first case, the syntax tree is DeclType( DeclRefExpression(“i”) ), in the second, it’s DeclType( ParenExpression( DeclRefExpression(“i”) ) ).

    The special part here are the rules for decltype. The decltype rules are as follows:

    1. If the expression is a function call, the result of decltype is the declared type of that function. E.g. given “int foo()”, decltype(foo()) is “int”. Given “int& foo()”, decltype(foo()) is “int&”.
    2. If the expression is a declaration reference expression, the result of decltype is the declared type of that declaration. Given “int i”, decltype(i) is “int”. Given “int& i”, decltype(i) is “int&”.
    3. If neither of the above applies and the expression is an lvalue, the result of decltype is an lvalue reference to the type of the expression. If the expression is an lvalue of type int, the result is “int&”.
    4. If none of the above rules apply, the result of decltype is the type of the expression. If the expression is an rvalue of type int, the result is “int”.

    In decltype(i), the expression is a declref to i. The type of i is int. Thus, decltype(i) is “int”.
    In decltype((i)), the expression is a parenexpr. It doesn’t matter what the parentheses contain – neither rule 1 nor 2 can apply. However, (i) is an lvalue, so rule 3 applies. The type of (i) is int, so decltype((i)) is “int&”.

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

Sidebar

Related Questions

Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like
Possible Duplicate: Transparent images with C# WinForms I am coding an app which will
Possible Duplicate: Javascript window resize event I want to get an event which is
Possible Duplicate: trailing return type using decltype with a variadic template function I want
Possible Duplicate: trailing return type using decltype with a variadic template function I'm getting
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are
Possible Duplicate: When do you use the “this” keyword? Hello, I understand that the
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#

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.