function-pointers

Variable Reference as Function Argument

我只是一个虾纸丫 提交于 2019-12-13 03:21:48
问题 All about a Zend Application with an action helper. I want to unset some pairs of an array by a function. helper: class Application_Controller_Action_Helper_TestHelper extends Zend_Contr[...] { public function direct(&$array) { if(isset($array['key'])) unset($array['key']); } } controller: $this->_helper->TestHelper($var); How could I get it working? 回答1: You must also pass it as reference : $this->_helper->TestHelper(&$var); UPDATE: Ups, I had my errors turned off. You (and now me) are

Function/Method pointers Pushed to a Deque

三世轮回 提交于 2019-12-13 01:05:41
问题 I am making a Queue for running functions. I put the functions that require being called into a std::deque<bool(*)()> Then I later on cycle through the deque calling each function and letting it run, sometimes even doing things based on the return. The problem I am having is actually with regards to placing these functions inside of the deque. I have this deque inside a class called A2_Game . I also have a class called Button . My code resembles the following: class Button { bool DoInput(); }

Insert function pointer into QMap (Qt)

无人久伴 提交于 2019-12-12 22:36:52
问题 I am creating sort of a router for REST API in Qt and I am facing problem with inserting the function pointer into the QMap. I have class IModule from which the other modules are derivated. Important lines of IModule.h are typedef QByteArray* (*IBusAction)(IBus * , ProxyRequest *); class IModule : public QObject { Q_OBJECT protected: QMap<QString , IBusAction > *m_actions; Then I have UserModule which is derived from IModule and in .cpp file I have these lines: QByteArray* UserModule::create

Array of methods in swift without reference cycle

限于喜欢 提交于 2019-12-12 21:15:31
问题 My goal is to create a class which contains an array. The elements of the array will be the methods of the same class. like: class MyClass { lazy var functions = [self.myFirstMethod, self.mySecondMethod] deinit { print("Deinit") } func myFirstMethod() { // Do Something } func mySecondMethod() { // Do Something } func executeAll() { for f in functions { f() } } } When I call the executeAll() it works fine and I achieve my expected result: var myObject = MyClass() myObject.executeAll() The

Conversion between function pointers with void and non-void pointer parameters

自闭症网瘾萝莉.ら 提交于 2019-12-12 18:15:24
问题 I have a question related to void pointer conversions. Instead of casting between void* and non-void pointers, my question is about casting between function pointer types, one of which has void* as parameter type and another has a pointer to some particular data type. Here's the code which allows to reproduce the warning messages: #include <stdio.h> typedef void (*module_outputMessage)(void *param, const char *msg); void module_function(module_outputMessage outputFunc, void *output_param, int

Warning (Anachronism): Assigning void(*)(int) to extern “C” void(*)(int)

时光毁灭记忆、已成空白 提交于 2019-12-12 18:08:32
问题 I'm having trouble with Sun's C++ compiler. I've read Oracle's Working with Pointers to Functions [from C++]. Its a good read, and I get the impression SunCC is most compliant among all the compilers in this area (though its causing me trouble). The test code is below, and line 24 is new_handler.sa_handler = (pfn ? pfn : &SignalHandler::NullHandler); . Unrolling the ternary operator shows this is the issue: new_handler.sa_handler = pfn; . SunCC 5.11 $ /opt/solstudio12.2/bin/CC test.cxx "test

SWIG call function pointers stored within struct

丶灬走出姿态 提交于 2019-12-12 17:40:58
问题 I have a struct as follows: struct power_model { int64_t (*estimate_energy)(statistics *stats, statistics *scaled_stats, parameters *from, parameters *to, energy_container *energy_container); int64_t (*estimate_performance)(statistics *stats, parameters *params); uint32_t (*freq_to_volt)(uint32_t freq); }; There are multiple power models that my code contains. I would like to wrap these models with SWIG and expose them to Python so that I can run my unit tests. While the SWIG documentation

Comparing std::function for member functions

前提是你 提交于 2019-12-12 15:25:21
问题 I tried to search and here similar questions: question 1 question 2 But anyway, I can't compare member functions. Here's an example: class ClassA { public: int add(int a, int b) { return a + b; } }; int main() { ClassA a1{}; function<int(int, int)> f1 = bind(&ClassA::add, a1, placeholders::_1, placeholders::_2); function<int(int, int)> f2 = bind(&ClassA::add, a1, placeholders::_1, placeholders::_2); cout << boolalpha << "f1 == f2 " << (f1.target_type() == f2.target_type()) << endl; // true

C++ Custom compare function for list::sort

ぃ、小莉子 提交于 2019-12-12 15:19:14
问题 Hi I'm having trouble compiling a simple piece of code. I am creating a class which implements a Deck of cards, and I want to create a shuffle method using the list::short method. Relevant code: deck.h #ifndef _DECK_H #define _DECK_H #include <list> #include <ostream> #include "Card.h" #include "RandomGenerator.h" using namespace std; class Deck { private: static const int CARD_NUMBER = Card::CARDS_PER_SUIT*Card::SUIT_NUMBER; list<Card *> *cards; RandomGenerator rg; public: Deck(); ~Deck();

how to set a int value passed by parameter to a function and assign it to global so I can use outside of the function?

扶醉桌前 提交于 2019-12-12 12:31:54
问题 how to set a int value passed by parameter to a function and assign it to global so I can use outside of the function? Example: int assignValues(int valor_assign1, valor_assign2){ valor_assign1 = 7; valor_assign2 = 3; } main (){ int valor1 = 0; int valor2 = 0; assignValues(valor1,valor2); printf("%d,%d",valor1, valor2); } The output is actually 0,0 I want it to be 7,3 how do I do this? I know its a simple question but I've been trying and searching but I can't find anything like that =/