Index ¦ Archives ¦ RSS

Pointers to member functions in C++

Estimated read time: 1 minutes

Okay, I learned something new, you can have a special pointer type in C++ which is not really a pointer at all.

So let's say you have a Foo class with a lot of void foo(int param); methods. Then you can have a "pointer" type 'int (Foo::*)(int)' which is in fact a pointer to Foo and it has an offset about what function does it point to.

And given that it contains an address and an offset as well, you can't cast it to void*, like you can do so with real pointers.

I had to look up the Bjarne book since I didn't really know about this at all... ;-)

© Miklos Vajna. Built using Pelican. Theme by Giulio Fidente on github.