FAQ Database Discussion Community


Trouble calling pointer to member function

c++,member-function-pointers
I'm trying to call a function pointer that points to a member function and I either get the error Error 3 error C2064: term does not evaluate to a function taking 0 arguments or Error 3 error C2171: '*' : illegal on operands of type 'Foo::func_t my code looks like...

c++ function ptr in unorderer_map, compile time error

c++,member-function-pointers
i am trying to implements an unorderer_map that implements as mapped_type, i was watching some examples that implements these but i cannot make it work. here is the code: #include<string> #include <unordered_map> namespace Test { class Example { public: Example() { auto aPair=std::make_pair("one",&Example::procesString); map.insert(aPair); } void procesString(std::string & aString) {...

Protected member function address in derived class is not accessible

c++,inheritance,protected,member-function-pointers
#include <iostream> class A { protected: void foo() {} }; class B : public A { public: void bar() { std::cout << (&A::foo) << std::endl; } }; int main() { B b; b.bar(); } Here I am trying to get address of protected member function of base class. I am...

passing member-function as argument to function-template

c++,templates,functor,member-function-pointers,template-function
Consider three ways to implement a routine in c++: through functors, member functions, and non-member functions. For example, #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class FOO { public: void operator() (string word) // first: functor { cout << word << endl; } void m_function(string word) //...

Declare and use a pointer to member function in another class

c++,pointers,function-pointers,member-function-pointers
I have this error, when I try to use a pointer to member function to a different class. Error : sources/common/OurMenu.cpp: In member function ‘void OurMenu::menuNavigation()’: sources/common/OurMenu.cpp:336:36: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((OurMenu*)this)->OurMenu::_buttons.std::vector::at >(((std::vector::size_type)((OurMenu*)this)->OurMenu::_actualLine))->Button::doIt (...)’, e.g. ‘(... ->* ((OurMenu*)this)->OurMenu::_buttons.std::vector::at...

C++ Callback Function to Member Function

c++,function,callback,member-function-pointers,member-functions
I have never worked with callbacks, but the following code should work according to my professor's notes. It doesn't like the template and has errors about "gauss cannot appear in a constant-expression." Note: GaussElim is a function object (gauss(mx, vector) works in previous code). The DirichletSolver templated callback function: template...

How to properly pass member function as argument in this situation in C++?

c++,functional-programming,function-pointers,member-function-pointers
I want to pass a member function of my C++ class to another member function of the same class. I did some research and found these similar questions on SO. C++ passing member function as argument C++, function pointer to member function They don't cover my specific case in an...

Create method argument with member function pointer from template types in C++ 11

c++,templates,function-pointers,member-function-pointers
I want to achieve the following: template <typename F> class MyTemplate { public: void SomeMethod(F f) { //... } template <typename C, typename O> void SomeMethod(C::*F f, O& o) { // this does not work, I want a member function pointer here //... } }; static void StaticFunction(int); class SomeClass...

Pointer to Class AND pointer to method

c++,member-function-pointers
how can I make double pointer to class and member function? Basically, I have some (quite a few) generic classes accepting function pointers like this: void Gen::regCallback(void (*callback)(void const *), void const * callbackData) and in classes, I often have either functions like this void Foo::doSomething(void const * instance) //...

C++ deduce member function parameters

c++,templates,function-pointers,member-function-pointers
I'm looking to extend the functionality described here but for member functions, what would be the syntax in this case? Also, the (*) in the template definition, is that de-referencing the function pointer so the compiler can deduce the template arguments? Would appreciate any input! Thanks template <class F> struct...