This is a page of miscellaneous topics, not all of them new, that we need to do before operator overloading.
this
is a pointer that points to the object that the member function belongs to.
this
is the invisible pointer that was passed to the member function.
this
exercise in
class point.
c++ -o ~/bin/obj main.C obj.C ls -l ~/bin/obj obj i = 10 etc.
.C files,
c++ main.C file1.C ls -l a.out ./a.out The f in main.C etc.The program contains two different functions with the same name,
f.
Normally, this would cause
c++
to give us the following error message:
multiple definition of `f()'
static
in the definition of the
f
in
file1.C,
the
f
defined in
file1.C
is the private, secret possesion of
file1.C.
f
will not interfere
with the
f
defined in
main.C.
f
defined in
file1.C
has
internal linkage
because of the keyword
static.
f)
cannot be mentioned in any other
.C
file of the program.
f
and
g
defined in
main.C
have
external linkage
because of the absence of the keyword
static.
f
and
g)
can be mentioned in other .C
files of the program.
static
from the above
file1.C
and observe the “multiple definition” error message
you get from
c++.
static.
inline1.C,
inline1.txt.
f
defined in
inline1.C
occupies very little memory,
and takes only a microsecond to execute.
f
and a microsecond to return from
f
(i.e., come back up).
f,
we spend two-thirds of our time on the road.
inline2.C,
inline2.txt.
f
in
inline2.C
is now an
inline function.
point
has an inline constructor,
an inline member function,
and an inline friend function.
c++ main.C point.C ls -l a.out ./a.out A = (3, 4) etc.
Compare our old class
point,
none of whose functions were inline:
increment1.C,
increment1.txt.
increment2.C,
increment2.txt.
=
executes
after
the increment operator
++.
See levels 2, 13, and 16 in the
table.
a.
a
by value to a function.
b
is passed to the function without being copied.
In the output file
main3.txt,
note that we create a copy of object
a:
the original is object number 1,
and the copy (with the same name,
a)
is object number 3.
But we do not create a copy of object
b.
c++ main.C announcer.C ls -l ./a.out