(member) function returning pointer to functions like itself?
Dima Volodin
dvv@dvv.org
Wed Mar 29 06:57:00 GMT 2000
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
More information about the Gcc
mailing list