Re: Questions about chapter 11 (Operator Overloading) of TC++PL.
Wayne Shu wrote:
On 10 23 , 5 09 , anon <a...@no.no> wrote:
Wayne Shu wrote:
Hi everyone, I am reading B.S. 's TC++PL (special edition).
When I read chapter 11 Operator Overloading, I have two questions.
1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,
operator =, operator[], operator(), and operator-> must be nonstatic
member function; this ensures that their first operands will be
lvalues". I know that these operators must be nonstatic member
functions, but why this ensure their first operands will be lvalues?
e.g.
class foo
{
int i;
public:
foo & operator = (int ii) { i = ii; return *this; }
The first operant is ii.
No.
};
foo bar() { return foo(); }
bar() = 10;
here bar() is a rvalue.
The first operant is 10, not bar()
No.
10 is a rvalue too.
Yes, but...
To 'anon':
When talking about binary operators (operators with two operands),
the "first" operand is the one that is shown/written to the *left*
when the operator is *being used*. So, when looking at the
expression
a = b
while discussing the assignment operator, 'a' is the _first_
operand and 'b' is the _second_. In C++ it translates so that the
*first* operand is the object for which the function operator= is
called, and the *second* is the actual argument of that function.
In the case above, whatever the subexpression 'bar()' yields would
be the _first_ operand. '10' would be the _second_ operand.
Just making sure we're using the correct terminology.
And, sorry, I don't have the answer to the original question.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask