member-function-pointers

How to call pointer to member function, which has been saved in a vector of custom struct? [closed]

点点圈 提交于 2019-12-08 14:08:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . My question is actually regarding already asked question. I have tried the answer given by @r3mus n0x also have seen some SO questions which did not help me to get a clear idea about the above situation. In the given post lacks MCVE, therefore I have tried a bit and came up with the following code and with the

How can I use a member function pointer in libcurl

杀马特。学长 韩版系。学妹 提交于 2019-12-07 14:32:58
问题 I am using libcurl I have my downloading of files inside of a class, to which I want to see a progress function. I notice I can set a typical function pointer by curl_easy_setopt(mCurl, CURLOPT_PROGRESSFUNCTION, progress_func3); However, I would like to set it to a function pointer to my class. I can get the code to compile with curl_easy_setopt(mCurl, CURLOPT_PROGRESSFUNCTION, &MyClass::progress_func3); and the progress_func3 function will get called. The problem is, as soon as it returns

C++ class member function and callback from C API

做~自己de王妃 提交于 2019-12-07 08:19:08
问题 I am trying to learn how to call this write_data(…) function from the funmain() function in the class as shown in the code bellow. (I know this program works if I just list these two functions without putting it inside a class). curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data) line gives me error and wouldn’t let me call the write_data(…) function. Can you please correct my code and tell me how I can achieve this. Any help would be greatly appreciated. Thanks. error C3867: 'go

C++ Map of string and member function pointer

此生再无相见时 提交于 2019-12-07 07:25:20
问题 Hey so I am making a map with string as the key and a member function pointer as the value. I can't seem to figure out how to add to the map, this doesn't seem to be working. #include <iostream> #include <map> using namespace std; typedef string(Test::*myFunc)(string); typedef map<string, myFunc> MyMap; class Test { private: MyMap myMap; public: Test(void); string TestFunc(string input); }; #include "Test.h" Test::Test(void) { myMap.insert("test", &TestFunc); myMap["test"] = &TestFunc; }

operator member_function_pointer_type() without typedef?

喜你入骨 提交于 2019-12-07 06:42:42
问题 Is it possible to make an operator member_function_pointer_type() without using typedefs (i.e. by specifying the type of the member function pointer inline)? For example, when implementing the Safe Bool Idiom: class Foo { typedef void (Foo::*bool_type)() const; public: operator bool_type() const; }; is it possible to write out the type of bool_type directly when declaring the operator? If so, how? 回答1: It seems that this is the only case where one cannot declare a (typecasting) operator

Pass member function pointer in C++

╄→尐↘猪︶ㄣ 提交于 2019-12-06 11:46:14
I am trying to pass a function pointer (of type QScriptEngine::FunctionSignature (= QScriptValue (QScriptContext *, QScriptEngine *) )) to an other function. But the function I need to pass is a member function of a class. I use it like this: class MyClass { SomeVarType someVarINeedAccessTo; QScriptValue print(QScriptContext* context, QScriptEngine* engine) { ... someVarINeedAccessTo ... } void someFunction() { QScriptEngine engine; QScriptValue printFunction = engine.newFunction(print); engine.globalObject().setProperty("print", printFunction); } }; With this example I get the error: error:

Member function pointer runtime error - The value of ESP was not properly saved across a function call

。_饼干妹妹 提交于 2019-12-06 11:18:47
问题 I've been searching for answers to this problem for the past hour but can't find a solution that works. I'm trying to use function pointers to call a non-static member function of a specific object. My code compiles fine, but during runtime I get a nasty runtime exception that says: Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with

Calling Member Function Pointers

怎甘沉沦 提交于 2019-12-06 01:31:38
I am having trouble calling a function pointer inside a structure. I have used this approach before outside of classes, but now that I am trying it inside a class method using function pointers to other class methods.... I am receiving a compiler error. Here is my class: class Myclass { int i; void cmd1(int) {} void cmd2(int) {} void trans() { const struct { std::string cmd; void (Myclass::*func)(int) } CmdTable[] = { { "command1", &Myclass::cmd1 }, { "command2", &Myclass::cmd2 } }; CmdTable[0].func(i); CmdTable[1].func(i); } }; The lines CmdTable[0].func(i); and CmdTable[1].func(i); both

Pointer to member function syntax

大兔子大兔子 提交于 2019-12-05 23:27:32
I'm trying to wrap my head around pointers to member functions and am stuck with this example: #include <iostream> class TestClass { public: void TestMethod(int, int) const; }; void TestClass::TestMethod(int x, int y) const { std::cout << x << " + " << y << " = " << x + y << std::endl; } int main() { void (TestClass::*func)(int, int) const; func = TestClass::TestMethod; TestClass tc; tc.func(10, 20); return 0; } What I think the code should do: In the first line of main I declare a pointer to a member function of class TestClass , which returns nothing/takes two int 's and is declared const ,

C++ Map of string and member function pointer

南笙酒味 提交于 2019-12-05 14:35:55
Hey so I am making a map with string as the key and a member function pointer as the value. I can't seem to figure out how to add to the map, this doesn't seem to be working. #include <iostream> #include <map> using namespace std; typedef string(Test::*myFunc)(string); typedef map<string, myFunc> MyMap; class Test { private: MyMap myMap; public: Test(void); string TestFunc(string input); }; #include "Test.h" Test::Test(void) { myMap.insert("test", &TestFunc); myMap["test"] = &TestFunc; } string Test::TestFunc(string input) { } See std::map::insert and std::map for value_type myMap.insert(std: