Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > why copy constr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 44797 of 48022
Post > Topic >>

why copy constructor is not being called?

by suresh <suresh.amritapuri@[EMAIL PROTECTED] > Apr 15, 2008 at 09:15 AM

Hi

Could you please tell why copy constructor is not called in the first
line in main(), as mentioned in the text books. I used g++ version
4.1.2 on debian etch

thanks
suresh

# include <iostream>
using namespace std;
class base
{
  char s;
public:
  base( ){cout<< "construction" << endl;}
  base(const char a ) {cout << "construction with arg" << endl;}
  base(const base & a){cout <<"copy constructor" << endl;}
  base & operator=(const base & a){cout << "assignment operator" <<
endl;}
  ~base( ) {cout << "destruction" << endl;}
};

main ( )
{
  base b1 = 'x'; //why copy constructor is NOT called here as given in
books?
  base b2 = b1; //copy constructor is called

}
 




 7 Posts in Topic:
why copy constructor is not being called?
suresh <suresh.amritap  2008-04-15 09:15:08 
Re: why copy constructor is not being called?
ltcmelo <ltcmelo@[EMAI  2008-04-15 09:23:16 
Re: why copy constructor is not being called?
Pete Becker <pete@[EMA  2008-04-15 12:32:43 
Re: why copy constructor is not being called?
Rolf Magnus <ramagnus@  2008-04-15 18:38:56 
Re: why copy constructor is not being called?
Pete Becker <pete@[EMA  2008-04-15 13:52:59 
Re: why copy constructor is not being called?
ltcmelo <ltcmelo@[EMAI  2008-04-15 09:51:23 
Re: why copy constructor is not being called?
Andrey Tarasevich <and  2008-04-15 10:58:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 11:36:31 CDT 2008.