Anteru's blog
  • Consulting
  • Research
    • Assisted environment probe placement
    • Assisted texture assignment
    • Error Metrics for Smart Image Refinement
    • High-Quality Shadows for Streaming Terrain Rendering
    • Hybrid Sample-based Surface Rendering
    • Interactive rendering of Giga-Particle Fluid Simulations
    • Quantitative Analysis of Voxel Raytracing Acceleration Structures
    • Real-time Hybrid Hair Rendering
    • Scalable rendering for very large meshes
    • Subpixel Reconstruction Antialiasing
    • Tiled light trees
  • About
  • Archive

C++ tricks, #4: Binding to overloaded member functions

May 17, 2007
  • Programming
approximately 1 minutes to read

Anyone who is developing with C++ knows the joys of member functions and pointers to member functions (you know, those SomeLongType (ClassName::*)(Param)-typed beasts). Today, I had a problem, I needed to bind (using Boost.Bind) to an overloaded member function, and to make things interesting it was const as well. The problem is with just a plain &Class::functionName (i.e., boost::bind (&Class::fun, &instance, _1, ...)), it cannot resolve which function you mean (giving you usually pages of compiler output). The deal is, how to disambiguate, and the solution is of course cast to your type. This leads to something like

boost::bind (static_cast<int (ClassName::*)(const Param& p1) const> (&ClassName::Function), &instance, _1)

Hope this helps somebody as it took me quite some time to figure this out.

Previous post
Next post

Recent posts

  • Five years of GPU DB
    Posted on 2020-09-27
  • Enabling SSL in your local network
    Posted on 2020-05-17
  • Goodbye, Bitbucket!
    Posted on 2020-03-19
  • QEMU, KVM and trim
    Posted on 2020-01-26
  • Fixing network after Ubuntu 19.04 to 19.10 upgrade
    Posted on 2019-10-26
  • Older posts

Find me on the web

  • GitHub
  • GPU database
  • Projects

Follow me

NIV_Anteru

Contents © 2005-2021 | Anteru | Imprint/Impressum | Privacy policy/Datenschutz