search
Login

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

0 votes
45 views
asked anonymous

1 Answer

0 votes
 
Best answer
The function call can appear on the left hand side of an assignment operator.

This ability may seem strange at first. For example, no one thinks the expression f() = 7 makes sense. Yet, if a is an object of class Array, most people think that a[i] = 7 makes sense even though a[i] is really just a function call in disguise (it calls Array::operator[](int), which is the subscript operator for class Array).

 class Array {
 public:
   int size() const;
   float& operator[] (int index);
   ...
 };
 
 int main()
 {
   Array a;
   for (int i = 0; i < a.size(); ++i)
     a[i] = 7;    // This line invokes Array::operator[](int)
   ...
 }
answered Advisor 5.6k points 1 7 14

Related questions

0 votes
1 answer 58 views
58 views
can anybody tell me What happens if you assign to a reference? thanks..
asked anonymous
1 vote
1 answer 3.8K views
3.8K views
please give me a defination of reference variable.
asked sandy Newbie 130 points 1 1 3
0 votes
2 answers 43 views
0 votes
1 answer 76 views
0 votes
1 answer 103 views
103 views
asked anonymous
...