Developer community
0 votes
42 views
asked by | 42 views

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 by Advisor (5.6k points) 1 7 14

Related questions

0 votes
1 answer
asked by anonymous | 57 views
+1 vote
1 answer
asked by sandy Newbie (130 points) 1 1 3 | 3.8k views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked by anonymous | 98 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


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

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users