hitz@csi.uottawa.ca (Martin Hitz) (06/26/91)
In the course of testing my understanding of the rules for argument matching
given in section 13.2 in the ARM, I tried to predict the outcome of the
program given below. In order to verify my conclusions, I tried the
program with 4 different compilers (GNU g++, Sun's cfront, Zortech, and
Borland C++). As the results have been somewhat arbitrary, I'd like to
get your comments on who's right:
#include <stream.h>
void f (const double &, double, void *) { cout << 1; }
void f (double &, int, const char * = 0) { cout << 2; }
void f (int) { cout << 3; }
void f (long, int = 0) { cout << 4; }
main ()
{
double b;
const double pi = 3.14;
// Z g++ cfront BC++
//---------------------------------------
f(1.1, 1, f); // 1 err err 1
f(1, 1, "Y"); // err err err 2
f(3, 1.1, 0); // err err 1 err
f(1.1, 3, (void*)0);// err 1 1 err
f(1, 1); // err 4 4 4
f(pi, pi, "Y"); // 1 1 1 err
f(0L); // 4 3 4 4
f(0L, 'a'); // err 4 4 4
f(pi); // err 3 err err
}
Thanks, Martin Hitz@csi.uottawa.ca