This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: (member) function returning pointer to functions like itself?


Well, I've ended up with

///////////////// cut /////////////////
#include <iostream>

class Fptr {
        class Fptr (*ptr) ();

public:
        Fptr (Fptr (*p) ()) : ptr (p) {}

        Fptr operator () () {
                return (*ptr) ();
        }
};

Fptr f1 ();
Fptr f2 ();

Fptr f1 () {
        cout << "f1" << endl;
        return f2;
}

Fptr f2 () {
        cout << "f2" << endl;
        return f1;
}

int
main () {
        Fptr f (f1);

        f = f ();
        f = f ();
        f = f ();
}
///////////////// cut /////////////////

but it's not exactly what I wanted - I get a pointer to a class here,
which is not as efficient as pointer to function. So the original
question still stands.

Cheers!

Dima

Dima Volodin wrote:
> 
> Consider:
> 
> ...
> T f1 ();
> T f2 ();
> ...
> T fN ();
> ...
> T f1 () {
>         ...
>         return f2;
> }
> ...
> T fN () {
>         ...
>         return f1;
> }
> ...
> T t;
> ...
>         t = (*t) ();    // I really want it like this
> ...
> 
> How do I define T?
> 
> Cheers!
> 
> Dima

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]