i have a complex function definition written in c++. It is the first time i have come across such a complex function definition and i am having trouble understanding the meaning of it.
Here it is
t_group& t_group::operator=(const t_group &a)
{
}
specifically i need to know what
operator=(const t_group &a)
mean ?
Here’s the breakdown:
The function returns a reference to a
t_group.The function is in the
t_groupnamespace. Sincet_groupis the name of astruct,union, orclass, it is a member oft_group.The function is an overload of the
=operator. Since it is a method, the object is the left-hand-side of the=operator.This is the parameter to the function: it’s the right-hand-side of the
=operator. This says the right-hand-side is aconstreference to at_group, which means the function will not alter thet_group.Taken together, this is the copy assignment operation for the
t_groupclass. It is invoked by code like:The latter line is equivalent to
b.operator=(a);.P.S. assignment operator functions typically end with
return *this;. This is so you can chain the assignments (e.g.a = b = c) just like the regular=operator.