xl
An Overture to C Programmers
int main() {
char buff[10];
int a = 1;
u
long b = 2;
v
unsigned long c = 3;
w
toa(a, buff, 10);
toa(b, buff, 10);
toa(c, buff, 10);
}
Listing 3: Calling overloaded functions
The data type of the first argument in each of the functions differs, so
the C++ compiler has enough information from
the arguments passed into
toa
to call the correct function. Each
toa
call is to a unique function. Here,
you create the variables
a
u
,
b
v
, and
c
w
, which are different types of
int
objects that correspond with one of the three
toa
functions.
This is more con-
venient than defining separately named functions, because you just need to
remember one name and the compiler figures out which function to call.
Dostları ilə paylaş: