Declaration and initialization of the same object name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • playincard
    New Member
    • Dec 2010
    • 1

    Declaration and initialization of the same object name

    Hi all,

    I'm reviewing some C++ notes and came across this line of code in a section demonstrating copy/assignment constructor use:

    Code:
    struct D {
      int i;
      B b1, b2;
    };
    
    int main() {
      D d = d;	// bitwise/memberwise copy
      d = d;	// bitwise/memberwise assignment
    }
    The second line in main() makes sense to me because the instance with name 'd' has already been defined.

    However, in the first line of main(), what is happening exactly? ? How can an instance of D with name 'd' be initialized with an instance of D also with name 'd'? Chicken or the egg?

    Thanks in advance
Working...