Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!zaphod.mps.ohio-state.edu!sample.eng.ohio-state.edu!purdue!svb From: svb@cs.purdue.EDU (Stephan Bechtolsheim) Newsgroups: comp.lang.c++ Subject: Overloading of functions with semi-identical signatures Message-ID: <14679@ector.cs.purdue.edu> Date: 21 May 91 03:42:11 GMT Sender: news@cs.purdue.EDU Organization: Department of Computer Science, Purdue University Lines: 57 Look at the following source code please: ----------------------------------------------------------------- #include // Have three functions with almost identical signatures. int F (int); int F (int &); int F (const int &); int F (int a) { cout << "int F (int) called, argument = " << a << "\n"; return 0; } int F (int &a) { cout << "int F (int &) called, argument = " << a << "\n"; return 0; } int F (const int &a) { cout << "int F (const int &) called, argument = " << a << "\n"; return 0; } int main() { // **************************************** // And here is a function call. WHICH F?!?! // **************************************** int k = F(12); // which F?! exit (0); } -------------------------------------------------------- Question 1: which F should the compiler pick? With g++ it pickes the first one, but WHY?! Question 2: C++ would not allow you to do this though: int F (const int); int F (const int a) { cout << "int F (const int) called, argument = " << a << "\n"; return 0; } Then g++ (1.37....) complains. Anyone any insight? Thanks. Stephan v. Bechtolsheim Computer Sciences Department svb@cs.purdue.edu Computer Science Building (317) 494 7802 Purdue University FAX: (317) 494 0739 West Lafayette, IN 47907