This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: (member) function returning pointer to functions like itself?
- To: gcc at gcc dot gnu dot org
- Subject: Re: (member) function returning pointer to functions like itself?
- From: Dima Volodin <dvv at dvv dot org>
- Date: Wed, 29 Mar 2000 09:57:50 -0500
- Newsgroups: comp.lang.c++.moderated
- Organization: Huh?
- References: <38E1C63B.6827CA77@dvv.org>
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