By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Declaration and initialization of the same object name

P: 1
Hi all,

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

Expand|Select|Wrap|Line Numbers
  1. struct D {
  2.   int i;
  3.   B b1, b2;
  4. };
  6. int main() {
  7.   D d = d;    // bitwise/memberwise copy
  8.   d = d;    // bitwise/memberwise assignment
  9. }
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
Dec 11 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.