achoi@cory.Berkeley.EDU (Andrew Choi) (10/12/90)
Hello world. This may be a simple question to most of you, but I just cannot figure it out. How do you define the operator which converts a class object to a pointer to a function returning int? More specifically, I want to do the following: Class A; int (*fp)(); fp = A; /* Needs user-defined conversion here */ fp(); I tried the followings: operator int (*)() { ... } operator int (*)()() { ... } // I think it's either this operator (int (*)())() { ... } // or this operator int (*())() { ... } However, g++ version 1.37.2 alpha 2 gives me parse errors on all 4 approaches. Does anyone know how to do this correctly? Is it legal or possible to define an operator which does the above conversion. Thank you very much for your help. Name: Andrew Choi Internet Address: achoi@cory.berkeley.edu Tel: (415)848-5658 #include <standard/disclaimer.h>
glenn@huxley.huxley.bitstream.com (Glenn P. Parker) (10/12/90)
In article <28717@pasteur.Berkeley.EDU>, achoi@cory.Berkeley.EDU (Andrew Choi) writes: > How do you define the operator which converts a class object to > a pointer to a function returning int? This may not be exactly what you wanted, but it works with cfront 2.0. I couldn't get it work without the typedef. class A { public: typedef int (*intfunc)(); intfunc f; operator intfunc() { return f; } }; -- Glenn P. Parker glenn@bitstream.com Bitstream, Inc. uunet!huxley!glenn 215 First Street BIX: parker Cambridge, MA 02142-1270