codingdir logo sitemap sitemap |

c++ defining a member-function pointer without knowing the type of the object

By : , Category : c++

Yes, use decltype:

void (std::remove_reference<decltype(*this)>::type::*function)(int, int);
ReLated :

You should not be assigning a function pointer to a void pointer.


There are lot of issues with the code:

class A {
      double * var = new double;
  1. What is var?
  2. You cannot initialize data inside a class like this (Use a constructor)

This works:

Fct thef;
GenericFunc<Fct, double, double>::F phi = &Fct::F;
double x = (thef.*phi)(1);

Online Demo

Yes, in C++11 it's possible, thanks to the "new" using:

template<typename T>
using TRAVERSAL_CALLBACK = void(*)(T &data);

Notice however that in C++ you'd probably just make the whole type of the callback a template, to allow the usage of other types of callable objects (functors, lambdas, ...).


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © All Rights Reserved .