Tricky Assignment
Now, let's look at the next line: s = n;. That looks harmless enough; it just copies one string, n, to another string, s.[12] But wait a second; how does the compiler know how to assign a value to a variable of a type we've made up?
[12] By the way, in case you're wondering what useful function this statement serves in the sample program, the answer is "none". It's just to illustrate how operator = works.
Just as the compiler will generate a version of the default constructor if we don't define one, because every object has to be initialized somehow, the ability to assign one value of a given type to a variable of the same type is essential to being a data type; therefore, the compiler will supply a version of operator =, the ...
Get Learning to Program in C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.