[comp.lang.c++] Addr overloaded member fcn on operator

daniel@vega.ucsc.edu (02/17/90)

/*
Does section 13.3 of Stroustrup's (2.0) reference on taking the
address of an overloaded function apply to member functions as
well as globals. If so, this should be valid. 
Apparently cfront fails to correctly select the overload function.
Can someone find an error in this code? If not, is this a
known cfront bug? The bug apparently manifests itself even if
only one overloaded addition operator is supplied. It also
manifests itself in the case of taking an overloaded function's
address by using it as a function parameter.
*/

struct S {
    int func(int)	{ return 1; }
    int func(void*)	{ return 2; }
} s;

struct A {} a;
struct B {} b;

int operator+(A, int (S::*)(int))
{
	return 1;
}

int operator+(B, int (S::*)(void*))
{
	return 2;
}

main()
{
	int i;

	i = a + S::func;	// Bad argument error from cfront
	i = b + S::func;	// Bad argument error from cfront
}

/*
Daniel Edelson
daniel@cis.ucsc.edu
*/

ark@alice.UUCP (Andrew Koenig) (02/18/90)

In article <10784@saturn.ucsc.edu>, daniel@vega.ucsc.edu writes:

> Does section 13.3 of Stroustrup's (2.0) reference on taking the
> address of an overloaded function apply to member functions as
> well as globals. If so, this should be valid. 
> Apparently cfront fails to correctly select the overload function.

Indeed, it is a bug.  I think it will be fixed in 2.1.
-- 
				--Andrew Koenig
				  ark@europa.att.com