S
suresh
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
}
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
}