Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] Serialization of function pointers
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-11-12 16:00:00


It can be done. I've wanted to add a "case study" to the documentation but never have gotten around to it.

Basically here is the procedure.

a) Use a function object rather than a function pointer. This should be easy to do.
b) derive your function object from a common base class make your function
a virtual member of this class
c) make sure that the common base class has at least one virtual function.
This makes it a polymorphic base class.
d) include a variable which is a pointer to the common base class - that
is a polymorphic pointer.
e) Assign a new function object of the desired derived type to the polymorphic
pointer.
f) Save the polymorphic pointer as you would any other polymorphic pointer.
g) Some other time and/or place, load the polymorphic pointer as you would
any other polymorphic pointer.
h) You can now call your original function through the pointer to it's base class

Note that this method is ocmplete portable at the compile level. Also
note that the function object calls are portable accross plattorms. That
is a function object saved on a VC platform can be loaded on a gcc
platform. The key requirement is that the function object be implemented
in both the savnig and loading programs.

Robert Ramey
  "elizabeta petreska" <elizabeta.petreska_at_[hidden]> wrote in message news:ff8898bd0911120255j621cbddyc5d3de7b94a13e6_at_mail.gmail.com...
  Hello everybody

  This is my first post to the list.
  Can I serialize C++ function pointer ? I search around and found that it could not be done ( although I am not sure ).
  If it can not be done, whats the explanation about it ?
  Thanks

------------------------------------------------------------------------------

  _______________________________________________
  Boost-users mailing list
  Boost-users_at_[hidden]
  http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net