# Callback Member Functions

**URL:** <https://discourse.glfw.org/t/callback-member-functions/156>\
**Category:** support\
**Created:** [May 15, 2004, 5:27pm UTC](https://discourse.glfw.org/t/callback-member-functions/156 "2004-05-15T17:27:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 15, 2004, 5:27pm UTC](https://discourse.glfw.org/t/callback-member-functions/156/1 "2004-05-15T17:27:52Z")

</div>

**anonymous** wrote on [Saturday, May 15, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/29f06761/#0d80):

I tried to make a member function of one of my classes into a callback function, but it gave me an error. Is there a way to have a callback member function?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 17, 2004, 1:07am UTC](https://discourse.glfw.org/t/callback-member-functions/156/2 "2004-05-17T01:07:40Z")

</div>

**[cozman](https://sourceforge.net/u/cozman/)** wrote on [Monday, May 17, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/29f06761/#0d80/f979):

Make the member function a static member function & it should work.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 17, 2004, 3:07pm UTC](https://discourse.glfw.org/t/callback-member-functions/156/3 "2004-05-17T15:07:24Z")

</div>

**anonymous** wrote on [Monday, May 17, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/29f06761/#0d80/c6ee):

That will work currently. But in the future I may decide to have multiple instantiations of this class. In that case, I will want to be able to control which object’s member function is set as the callback function.

Also I don’t like static members because they are too global…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 17, 2004, 3:09pm UTC](https://discourse.glfw.org/t/callback-member-functions/156/4 "2004-05-17T15:09:08Z")

</div>

**anonymous** wrote on [Monday, May 17, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/29f06761/#0d80/f362):

That will work currently. But in the future I may decide to have multiple instantiations of this class. In that case, I will want to be able to control which object’s member function is set as the callback function.

Also I don’t like static members because they are too global compared to non-static members. I don’t need or want my callback functions to be that global.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 18, 2004, 3:58am UTC](https://discourse.glfw.org/t/callback-member-functions/156/5 "2004-05-18T03:58:27Z")

</div>

**nobody** wrote on [Tuesday, May 18, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/29f06761/#0d80/e239):

Look into functors, it allows you to link a callback function to any member function.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 20, 2004, 7:17am UTC](https://discourse.glfw.org/t/callback-member-functions/156/6 "2004-05-20T07:17:04Z")

</div>

**[the\_speed\_bump](https://sourceforge.net/u/the_speed_bump/)** wrote on [Thursday, May 20, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/29f06761/#0d80/ef28):

I would like to see this supported as well.

All that’s really required is that every callback have accompanying user data that’s big enough for a pointer.&nbsp; From there, it’s easy enough to write a C stub that relays to the proper method.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 21, 2004, 7:03am UTC](https://discourse.glfw.org/t/callback-member-functions/156/7 "2004-05-21T07:03:58Z")

</div>

**[marcus256](https://sourceforge.net/u/marcus256/)** wrote on [Friday, May 21, 2004](https://sourceforge.net/p/glfw/discussion/247562/thread/29f06761/#0d80/ef28/d242):

Hi! This [user data in callbacks] is actually a planned feature. It may not appear anytime soon since it would wreck the 2.x API, but I realize that it’s an important feature, especially when/if support for multiple windows appear (you may want to use the same callback for multiple windows).
