Function Overloading - Function Overloading Suppose that...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Function Overloading Suppose that you are writing some software to manipulate calendar dates, and you wish to allow a user of the software to specify dates in one of two forms: 8, 4, 1964 (as a triple of numbers) August 4, 1964 (as a string) In C, if there is a function to convert a raw date into an internal form (for example, the number of days since January 1, 1800), it might look like: long str_to_date(int m, int d, int y) { . .. } long str_to_date(char* d) { . .. } with one function for each of the two types of dates. Unfortunately, this usage is illegal in C, because two different functions cannot have the same name "str_to_date". In C++ this usage is legal and goes by the term "function overloading". That is, two or more functions may have the same name, so long as the parameter types are sufficiently different enough to distinguish which function is intended. A function may not be overloaded on the basis of its return type. The question of what makes two function parameter lists sufficiently different is an
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 2

Function Overloading - Function Overloading Suppose that...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online