This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: sorry not implemented: address of bound pointer-to-member function
- To: egcs mailing list <egcs at cygnus dot com>
- Subject: Re: sorry not implemented: address of bound pointer-to-member function
- From: "A.P. Zijlstra" <peter at mcs dot nl>
- Date: Tue, 29 Sep 1998 18:15:46 +0200
- Organization: Physics student @ University of Amsterdam
- References: <Pine.GSO.3.95.980929124021.3029A-100000@mumrik.nada.kth.se>
- Reply-To: peter at mcs dot nl
Fredrik Öhrström wrote:
>
> On Mon, 28 Sep 1998, A.P. Zijlstra wrote:
>
> > Also could someone explain the exact meaning of this message to me. The
> > thing triggering all this is trying to pass the address of a virtual
> > function member to some C-function.
>
> Pointers to member functions are special because they need to
> store both the object instance to call and the function.
> These pointers are essentially impossible to typecast because of
> the tight binding to a particular object. Here is an example how to
> get a method pointer and how to call it:
>
<snip example>
As said in the reply to Alexandre you rightly point to the complexity of
the problem. But getting a method pointer and calling it isn't quite
what i need. I'll be a bit more specific: (example following)
#include <glut.h> // C-api: OpenGL Utility Toolkit
// class intended as a base for more specific viewports eg. cameras
// hence the virtual functions
class GLviewport {
friend GLwin;
protected:
virtual void redraw() const {
...some DEFAULT code that redraws the viewport...
};
virtual void resize( int w, int h) const {
...some more DEFAULT code...
};
};
// class which manages the actual window
class GLwin {
public:
select( const GLviewport * viewport) {
...
glutDisplayFunc( viewport->redraw);
glutReshapeFunc( viewport->resize);
...
};
};
--eoe--
where the glut*Func functions take function pointer of the form:
Display: void (*func)(void)
Reshape: void (*func)(int, int)
as this doens't work (therefore this thread :), I tried the following
code-around:
class GLwin {
protected:
+ static GLviewport * __active_viewport;
+
+ static void _redraw_wrapper() {
+ __active_viewport->redraw();
+ };
+ static void _resize_wrapper( int w, int h) {
+ __active_viewport->resize( w, h);
+ };
public:
select( const GLviewport * viewport) {
+ __active_viewport = viewport;
...
// might actually be moved out of here as the address
// of the wrappers doens't quite change that often :)
| glutDisplayFunc( _redraw_wrapper);
| glutResizeFunc( _resize_wrapper);
...
};
};
which to my suprise doesn't work either !!! what happens is that the
functions called by the wrappers are the DEFAULT functions supplied in
GLviewport, not the functions specified in the classes derived from it
(eg. GLcamera). HOW CAN THIS BE ???
anywayz,.. enough of my rambling. Does someone have any idea, as I don't
:)
thanks for reading,
Peter
PS. I made a typo (if it can actually be called that) in the exact
message. it is: "sorry not implemented: address of bound
pointer-to-member EXPRESSION".