[comp.lang.c++] Pointers to Inline Members

rme@wdl1.UUCP (Richard M Emberson) (08/27/88)

	As a solution to a design problem, I would like to take pointers
	to memeber functions. I have heard ("The Evolution of C++:
	1985 to 1987" by B.S.) that with version 2.0 this will be
	possible.

	Question: What about pointers to inline function members? 

	Is this disallowed or should C++ keep "real" functions of
	all the inline functions so that pointers to them can still be
	taken.

						Richard M. Emberson, Jr.

flaps@dgp.toronto.edu (Alan J Rosenthal) (08/27/88)

In article <3690002@wdl1.UUCP> rme@wdl1.UUCP (Richard M Emberson) writes:
>Question: What about pointers to inline function members? 
>
>Is this disallowed or should C++ keep "real" functions of
>all the inline functions so that pointers to them can still be
>taken.

It seems that the current C++ compiler (at my site) handles this
correctly, just like with pointers to consts, for example -- it creates
an actual C-language object if and only if its address is taken.

While testing this, I found the compiler unwilling to take a local
declaration of the form:
	int (*f)(int);
, and when looking through Stroustrup to try to find what I did wrong,
this seemed to be right but I couldn't find any example of it!  He
seems always to declare function-pointers outside of functions, i.e. as
external variables.  Furthermore, the compiler DOES accept:
	auto int (*f)(int);
as a local declaration.

Any clues?  I'm using cfront 1.2.1 2/16/87, according to the usage
message.  The actual program used is the following, which fails to
compile when the word ``auto'' is removed.  As shown it correctly
outputs "3 4".

#include <stream.h>

class classname {
public:
    int f(int x) { return x; }
};

int main()
{
    class classname xxx;
    auto int (classname::*g)(int);

    cout << xxx.f(3) << " ";
    g = &(classname::f);
    cout << (xxx.*g)(4) << "\n";

    return 0;
}

ajr

--
owotd (rot13): fabgentf

bs@alice.UUCP (Bjarne Stroustrup) (08/28/88)

You have always been able to take the address of an inline function.
In that case the compiler must somehow lay down code for the pointer
to point to. Even 1.0 did that. 1.1 did that for inline members too.
You don't have to wait for 2.0 for that.

A similar trick is employed to let you take the address of a const.