In C++, if a class has a reference data member the default assignment operator is not synthesized by compiler. Why?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What an copy assignment should do is defined in:
C++03 Standard 12.8/13:
In short It implies that each of the member should assigned in an appropriate manner
which raises the question,
What should be the behavior for assignment of a reference member in class?
Consider the following about references:
#1assigning to an reference doesn’t reassign the reference, it changes the value of the referrant which is non-intuitive behavior.There is no default correct behavior to be enforced here but a rather situational one.So the C++ Standard mandates that designer of the class is in best position to determine this behavior and hence the decision that default assignment operator should not be synthesized by compiler if a class has a reference data member.
This decision is specified in:
C++03 Standard 12.8/12:
[Ref 1]
C++03 Standard 8.5.3/2: