Overloading methods in C API

James Kew james.kew at btinternet.com
Sat Jan 18 15:31:34 EST 2003


Grant Edwards wrote:
> In article <Xns9307CD595EDCBrcamesz at amesz.demon.nl>, Robert Amesz
> wrote:
>> No, it's not "looked down upon". Take, for example, the % operator
>> for strings: it allows things like:
>
> That's operator overloading, which I think of as different than
> function/method overloading.

Yes and no. Operator overloading allows you to provide your own definitions
for operators. Method overloading allows you to provide multiple versions of
a method for different argument types.

Operator overloading is directly supported in Python. Method overloading
isn't, but Robert's examples -- using the % operator on string with integer,
sequence, and directory arguments -- illustrates how Python methods can
simulate it by being liberal in what they accept.

> For whatever historical reasons, operator overloading and
> function/method overloading are usually considered as two separate
> language features.  C and python have the former but not the latter.

*cough* C has neither.

--
James Kew
james.kew at btinternet.com






More information about the Python-list mailing list