The following C++ program compiles without warning message
under RedHat 9.4 with a recent version of g++:
// all put in file main.cpp for simplicity
#include <stdio.h>
class MyClass
{
public:
void func (int);
void func (int&);
}
void MyClass::func (int x) { printf ("arg: %d\n", x); }
void MyClass::func (int x&) { x = 10; }
void main ()
{
MyClass mc;
mc.func (33); // legal: 1st func called, 'arg: 33' is printed
int x = 42;
// mc.func (x); // error: compiler can't tell which func to call
}
Leaving aside the matter of whether or not the above represents
a good design (it doesn't) or is strictly legal under the
specification
(it is, as far as I can tell), the above code does in fact compile, so
g++ evidently has a way of telling these two functions apart when
the class is defined.
However, I have not been able to find a way to explicitly invoke the
1st func or the 2nd func at will with an int variable inside main.
Any ideas?
Thank you,