mirror of
https://gitlab.com/fbb-git/cppannotations
synced 2024-11-18 10:06:54 +01:00
WIP
git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@307 f6dd340e-d3f9-0310-b409-bdd246841980
This commit is contained in:
parent
f5539539f2
commit
195a03ff43
4 changed files with 16 additions and 12 deletions
|
@ -77,6 +77,7 @@ COMMENT( 9 )
|
|||
lchapter(EXCEPTIONS)(Exceptions)
|
||||
includefile(exceptions)
|
||||
|
||||
COMMENT(>>>>>>>>>>>>> NEXT <<<<<<<<<<<<<)
|
||||
COMMENT( 10 )
|
||||
lchapter(OVERLOADING)(More Operator Overloading)
|
||||
includefile(overloading)
|
||||
|
|
|
@ -2,6 +2,7 @@ INCLUDEFILE(mailus)
|
|||
|
||||
includefile(overloading/more)
|
||||
|
||||
COMMENT(>>>>>>>>>>>>> NEXT <<<<<<<<<<<<<)
|
||||
lsect(OPERATORINDEX)(Overloading `operator[]()')
|
||||
includefile(overloading/array)
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
As our next example of operator overloading, we present a class
|
||||
operating on an array of tt(int)s. Indexing the array elements occurs with
|
||||
the standard array operator tt([]), but additionally the class checks for
|
||||
i(boundary overflow). Furthermore, the i(index operator) (ti(operator[]())) is
|
||||
interesting in that it both em(produces) a value and em(accepts) a value, when
|
||||
used, respectively, as a emi(right-hand value) (emi(rvalue)) and a
|
||||
emi(left-hand value) (emi(lvalue)) in expressions.
|
||||
Here is an example showing the use of the class:
|
||||
As our next example of operator overloading, we introduce a class tt(IntArray)
|
||||
encapsulating an array of tt(int)s. Indexing the array elements is possible
|
||||
using the standard array index operator tt([]), but additionally checks for
|
||||
i(array bounds overflow) will be performed. Furthermore, the
|
||||
i(index operator) (ti(operator[])) is interesting in that it can be used in
|
||||
expressions as both i(lvalue) and as i(rvalue).
|
||||
|
||||
Here is an example showing the basic use of the class:
|
||||
verb(
|
||||
int main()
|
||||
{
|
||||
|
@ -15,9 +15,11 @@ used, respectively, as a emi(right-hand value) (emi(rvalue)) and a
|
|||
x[i] = i * 2; // assign the elements
|
||||
|
||||
for (int i = 0; i <= 20; i++) // produces boundary overflow
|
||||
cout << "At index " << i << ": value is " << x[i] << endl;
|
||||
cout << "At index " << i << ": value is " << x[i] << '\n';
|
||||
}
|
||||
)
|
||||
COMMENT(>>>>>>>>>>>>> NEXT <<<<<<<<<<<<<)
|
||||
|
||||
First, the constructor is used to create an object containing 20
|
||||
tt(int)s. The elements stored in the object can be assigned or retrieved: the
|
||||
first tt(for)-loop assigns values to the elements using the index operator,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Having covered the i(overloaded assignment) operator in chapter ref(MEMORY),
|
||||
Having covered the overloaded assignment operator in chapter ref(MEMORY),
|
||||
and having shown several examples of other overloaded operators as well (i.e.,
|
||||
the insertion and extraction operators in chapters ref(FirstImpression) and
|
||||
ref(IOStreams)), we will now take a look at several other interesting examples
|
||||
of i(operator overloading).
|
||||
ref(IOStreams)), we will now take a look at i(operator overloading) in
|
||||
general.
|
||||
|
|
Loading…
Reference in a new issue