Reputation: 2023
class A
{
std::string name;
public:
A(const A & rhs)
{
name = rhs.name;
}
};
In copy constructor of class A above, will the assignment operator of string class is called or copy constructor of string class?
name data member is not defined yet, so wouldn't the copy constructor be called?
Upvotes: 0
Views: 110
Reputation: 5856
A default (compiler-generated) assignment operator will be called that does a member-by-member assignment
Upvotes: 0
Reputation: 6040
Assignment operator. If you want copy constructor:
A(const A& rhs)
: name(rhs.name)
{
}
Upvotes: 4