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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:36:11+00:00 2026-06-18T02:36:11+00:00

Why does the first commented line compile correctly, whereas the second doesn’t? Why can

  • 0

Why does the first commented line compile correctly, whereas the second doesn’t?

Why can a be given itself as a constructor argument, but b can’t?
Aren’t the two doing the same thing?

class Foo { Foo &operator =(Foo const &); /* Disable assignment */ };

int main()
{
    Foo a = a;  // OK
    Foo  b(b);  // error C2065: 'b' : undeclared identifier
}

Update

Since it seems like it’s compiler-dependent, it seems like the problem is more severe than I thought.
So I guess another part of the question is, is the following code valid or no?

It gives an error in GCC but Visual C++ executes it just fine.

int main()
{
    int i = 0;
    { int *i(&i); }
    return i;
}
  • 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-18T02:36:12+00:00Added an answer on June 18, 2026 at 2:36 am

    In your first code, both declarations should compile. GCC is right there. Visual C++ Compiler has bug.

    And in the second code, the inner declaration should not compile. GCC is right there too, and VC++ is wrong.

    GCC is right in both cases.

    A code like int a=a+100; and int a(a+100); is fine from syntax point of view. They might invoke undefined behavior depending on whether they’re created in static storage duration or automatic storage duration.

    int a = a + 100; //well-defined. a is initialized to 100
                     //a on RHS is statically initialized to 0
                     //then a on LHS is dynamically initialized to (0+100).
    void f()
    {
       int b = b + 100; //undefined-behavior. b on RHS is uninitialized
    
       int a = a + 50; //which `a` is on the RHS? previously declared one?
                       //No. `a` on RHS refers to the newly declared one.
                       //the part `int a` declares a variable, which hides 
                       //any symbol with same name declared in outer scope, 
                       //then `=a+50` is the initializer part.
                       //since a on RHS is uninitialized, it invokes UB
    }
    

    Please read the comments associated with each declaration above.

    Note that variables with static storage duration is statically initialized to zero at compile time, and if they’ve initializer, then they’re dynamically initialized also at runtime. But variables of POD types with automatic storage duration are not statically initialized.

    For more detail explanation on static initialization vs dynamic initialization, see this:

    • What is dynamic initialization of object in c++?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does the first code print DCBA and the second ABCD? Is 0x44434241 not
Why does the first if statement evaluate to true? I know if I use
Two related questions. First: does this repro for you or is it something local
What the title says. Are they the same? I've noticed that the first does
When calling loadClass() on a ClassLoader , does the ClassLoader first check if the
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,
Does someone know why i never get the first value of my array? it
Does anyone know how to test for the first member and last member in
Does Lua provide a function to make the first character in a word uppercase
Does the following code contain a memory leak of the first three characters in

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.