Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. question regarging callback functions

question regarging callback functions

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    namaskaaram
    wrote on last edited by
    #1

    why should a call back function be static when its called from an another class? say we have a class A and class B assume that class A calls a function in B say "b" and passes the address of an another function in A say "a". then to get get this working why is it a must that the function "a" be static.....we are passing the address of the member function as whole rt?..... :confused:

    C 1 Reply Last reply
    0
    • N namaskaaram

      why should a call back function be static when its called from an another class? say we have a class A and class B assume that class A calls a function in B say "b" and passes the address of an another function in A say "a". then to get get this working why is it a must that the function "a" be static.....we are passing the address of the member function as whole rt?..... :confused:

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      namaskaaram wrote:

      why should a call back function be static when its called from an another class?

      It is not only when it has to be called from another class: it is whenever your callback function is a member function of a class. The difference between static member functions and non-static member functions is that for the non-static one, there is an implicit parameter that is passed to the function: the address of the instance of your class (the this pointer). As static member functions are shared across all instances of your class (and thus don't belong to a particular instance, thus cannot access non-static data from one instance), there is no implicit 'this' parameter that is passed. This of course change the prototype of the callback function (because of the implicit parameter), that's why static and non-static member functions behave differently.


      Cédric Moonen Software developer
      Charting control

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups