function-pointers

Calling C++ member function pointer from a struct

…衆ロ難τιáo~ 提交于 2019-12-22 05:19:06
问题 I have found information on calling C++ member function pointers and calling pointers in structs, but I need to call a member function pointer that exists inside of a structure, and I have not been able to get the syntax correct. I have the following snippet inside a method in class MyClass: void MyClass::run() { struct { int (MyClass::*command)(int a, int b); int id; } functionMap[] = { {&MyClass::commandRead, 1}, {&MyClass::commandWrite, 2}, }; (functionMap[0].MyClass::*command)(x, y); }

How to address C4191 warning around calls to GetProcAddress with FARPROC?

雨燕双飞 提交于 2019-12-22 04:26:29
问题 Recently I tried to use /Wall Visual C++ option to enable all warnings and found that the following code: typedef BOOL ( WINAPI * TIsWow64ProcessFunction )( HANDLE, BOOL* ); TIsWow64ProcessFunction isWow64ProcessFunction = reinterpret_cast<TIsWow64ProcessFunction> ( ::GetProcAddress( kernel32DllHandle, "IsWow64Process" ) ); spawned C4191: warning C4191: 'reinterpret_cast' : unsafe conversion from 'FARPROC' to 'TIsWow64ProcessFunction' Calling this function through the result pointer may cause

Passing any function as a template parameter?

蹲街弑〆低调 提交于 2019-12-22 00:34:34
问题 I am looking for a way to pass a generic (constexpr, obviously) function to a template. It has to be able to take any amount of parameters, without using a lambda. This is what I have so far: template<typename T, T(*FUNC)()> struct CALL { static inline constexpr decltype(FUNC()) EXEC() { return FUNC(); } }; This however only works if the passed function takes no parameters. Is there a way to make the template accept ANY constexpr function? Passing a std::function does not seem to work. I

Pointer to function to member function

萝らか妹 提交于 2019-12-21 20:27:01
问题 I want to use a library (nlopt) that has a function set_min_objective which takes a pointer to a numerical function myfunc and find its minimum. I would like to create a class that will contain a suitably initialized member function. set_min_objective would then find an optimum in a specific instance (myP in the example below). The call sequence is: opt.set_min_objective(myfunc, NULL); and I would like to use something like: opt.set_min_objective(myP.f, NULL); the error I get when compiling

Calling a DLL function that contains a function pointer from C#

有些话、适合烂在心里 提交于 2019-12-21 17:54:37
问题 I have a DLL that is written in C++ that includes exported function that has a function pointers to be used as callback function. // C++ DllExport unsigned int DllFunctionPointer( unsigned int i, unsigned int (*TimesThree)( unsigned int number ) ) { return TimesThree( i ) ; } I have a CSharp application that I would like to use to invoke the DLL functions. // C# public unsafe delegate System.UInt32 CallBack( System.UInt32 number ); class Program { [DllImport("SimpleDLL.dll")] public static

define a function alias in VBA, possible?

社会主义新天地 提交于 2019-12-21 13:18:06
问题 I am using VBA behind MS Access Say I have global methods foo1 and foo2 that gets the same arguments but do different things. I know that in C++ I can assign a function an alias. Something like: instead of: If (term) then foo1 arg1, arg2, arg3 else foo2 arg1, arg2, arg3 End If I want to write: Var new_func = Iff (term, foo1,foo2) new_func arg1, arg2, arg3 Can I do this on vba? 回答1: Would Run suit? new_func = IIf(term, "foo1", "foo2") ''new_func arg1, arg2, arg3 res = Run(new_func, "a", "b", 1

why is the address of a c++ function always True?

做~自己de王妃 提交于 2019-12-21 13:13:33
问题 well why would, #include <iostream> using namespace std; int afunction () {return 0;}; int anotherfunction () {return 0;}; int main () { cout << &afunction << endl; } give this, 1 why is every functions address true? and how then can a function pointer work if all functions share (so it seems) the same addresss? 回答1: The function address isn't "true". There is no overload for an ostream that accepts an arbitrary function pointer. But there is one for a boolean, and function pointers are

why is the address of a c++ function always True?

一曲冷凌霜 提交于 2019-12-21 13:12:13
问题 well why would, #include <iostream> using namespace std; int afunction () {return 0;}; int anotherfunction () {return 0;}; int main () { cout << &afunction << endl; } give this, 1 why is every functions address true? and how then can a function pointer work if all functions share (so it seems) the same addresss? 回答1: The function address isn't "true". There is no overload for an ostream that accepts an arbitrary function pointer. But there is one for a boolean, and function pointers are

Does C++ support member function references?

故事扮演 提交于 2019-12-21 09:39:14
问题 C++ permits function pointers and function references. It also permits pointers-to-member-functions . But does it permit references-to-member-functions ? I can't seem to deduce the rules from the standard, and I've failed to make a program work with them. [ member function pointers ] [ member function references ] 回答1: [C++11: 8.3.3/3]: A pointer to member shall not point to a static member of a class (9.4), a member with reference type, or “ cv void.” [ Note: See also 5.3 and 5.5. The type

C++ Function pointers with unknown number of arguments

六月ゝ 毕业季﹏ 提交于 2019-12-21 09:21:15
问题 I need some help with C++, please! I'm writing a command parser for a small text-based game, and I've run into some problems. The parser is supposed to read and parse commands entered by the player. The most obvious and straightforward solution to this could be something like this (written in pseudo-code): command <- read input from the player if command == COMMAND1 do command1 else if command == COMMAND 2 do command2 ... I'm writing in C++, so I was thinking I could solve this by using an