function-pointers

0xC0000005: Access violation executing location 0x00000000. When trying to access the insert function of multimap

白昼怎懂夜的黑 提交于 2019-12-12 03:38:26
问题 I was coding for one of the problems in USACO Training Page, and when I tried to debug my code: #include <iostream> #include<fstream> #include<string> #include<map> #include<math.h> using namespace std; int translate(string &s) { int n = s.length(); int result = 0; for (int i = 0; i < s.length(); i++) { int n1 = 0; if (s.at(i) == 'Q' || s.at(i) == 'Z') { return -1; } switch (s.at(i)) { case 'A': case 'B': case'C': result = result + 2 * pow(10, n-1); n--; break; case 'D': case 'E': case'F':

Initialize member functions via constructor

倖福魔咒の 提交于 2019-12-12 02:23:30
问题 Perhaps I am way out of left field with this question, but is it possible to define a member function via the constructor? In my case, I am trying to write a class to perform robust model fitting (using RANSAC). I want this to be generalizable to different types of models. For example, I could use this to determine an estimate of a plane to a set of 3D points. Or, perhaps I could determine a transformation between two sets of points. In these two examples, there might need to be different

Using ofstream* wrapper class with overloaded << operator on endl

谁说我不能喝 提交于 2019-12-12 02:22:31
问题 C++ This is an attempt to make a class that mimics the output behavior of using the << operator of an ofstream , as far as being able to use std::endl and write string s is concerned. The class has a single data member, the ofstream pointer. The class has two overloaded << operators, one that takes an std::string and another that takes a pointer to a function, whose argument is an ostream reference and returns an ostream reference. That is the signature of std::endl , according to this.

Callback function C++

♀尐吖头ヾ 提交于 2019-12-11 20:37:42
问题 I'm having a great deal of problems trying to make a callback system. I want to pass a function to another class's function to receive data. I want ExampleClass to call SeperateThread::operate , and I want SeperateThread::operate to be able to call ExampleClass::updateNumber(int) to return a value. I've been trying for hours with various function pointers etc but can't seem to get it to work. SeperateThread is another thread so it doesn't block the main thread that ExampleClass is running in,

Cast function pointers that differs by argument type

一曲冷凌霜 提交于 2019-12-11 20:18:30
问题 Why this is not legal: class Base { public: Base(){}; virtual ~Base(){}; }; class Derived : public Base{}; void takeDerived(Derived * c){}; // main void(*ptr)(Base*) = static_cast<void(*)(Base*)>(&takeDerived); // doesn't work // but this work ok, as well as reinterpret_cast // void(*ptr)(Base*) = (void(*)(Base*))(&takeDerived); Derived is a Base . Why can't it be casted in function parameter? For example, I can do this easily even without casting: void takeBase(Base* c){}; takeBase(new

How to find the address & length of a C++ function at runtime (MinGW)

淺唱寂寞╮ 提交于 2019-12-11 19:19:57
问题 As this is my first post to stackoverflow I want to thank you all for your valuable posts that helped me a lot in the past. I use MinGW (gcc 4.4.0) on Windows-7(64) - more specifically I use Nokia Qt + MinGW but Qt is not involved in my Question. I need to find the address and -more important- the length of specific functions of my application at runtime, in order to encode/decode these functions and implement a software protection system. I already found a solution on how to compute the

What is the correct pointer type to return from a ctypes callback?

我怕爱的太早我们不能终老 提交于 2019-12-11 18:14:15
问题 I have a ctypes callback that takes a pointer to two doubles from the dll and returns a pointer to two doubles back to the .dll. The first part works correctly, but after a lot of testing and research, I still can't get the correct pointer to return to the .dll after the callback. Here's the ctypes callback code: from scipy.integrate import dblquad import ctypes LibraryCB = ctypes.WINFUNCTYPE(ctypes.py_object, ctypes.POINTER(ctypes.c_double)) def LibraryCall(ptr): n = ctypes.cast(ptr,ctypes

C: How to access a function pointer stored in a void pointer (void *)?

大憨熊 提交于 2019-12-11 17:53:06
问题 Confused as to how one can access a function pointer stored in a void pointer (void *). Let's say you have this: void *functions[] = { &sqrt, // int ft_sqrt(int nb); &power, &logN, &factorial; }; // An array of void pointers, each storing a function pointer. If I wanted to access the sqrt function, my guess would be the following: (int (*)(int)) functions[0](x) But my guess is wrong: error: called object type 'void *' is not a function or function pointer So how would one access one of these

Is There a declval for Function Pointers?

泄露秘密 提交于 2019-12-11 17:51:33
问题 I have a function and I need to test whether I can pass an argument of a given type to it. For example: template<typename T, auto F> decltype(F(declval<T>{})) foo(); Calling foo<int, bar>() does 2 things: Sets the return type of foo would have the same return type as bar Ensures that bar is a function that accepts an argument of type T Unfortunately I don't have access to auto template types, but I still want to accomplish both of these. What I need is a decltype for function pointers, which

How much memory is used for function references in a Java object?

泄露秘密 提交于 2019-12-11 15:35:23
问题 Is it 32-bit / 64-bit depending on the JVM, or is it less as do we really need that many possibilities for addresses when addressing functions? Surely we would never need that many possibilities as the number of types, and resulting number of functions would never reach these numbers? 回答1: The by far simplest implementation uses the "real"/full address of the function, whatever that may be on the architecture in question (e.g. the virtual address of the first instruction of the function