4,483 questions
1
vote
1
answer
48
views
Call function by reference in PowerShell [duplicate]
Suppose I have a function like this. How can I get a reference to that function and then call it?
function Hello($name) {
Write-Output "Hello, $name"
}
0
votes
1
answer
104
views
How do I store a function pointer to a public member function of a derived class?
I have a Base class with a few methods of identical signature, and a few Derived classes. Program logic chooses which Derived class to use, which method to use, and never changes these decisions later....
1
vote
1
answer
119
views
Modernizing typedef for a function to std::function [duplicate]
I have legacy code which uses typedef for function pointers (and yes, void* as well). I reduced it to this:
#include <memory>
#include <functional>
typedef void (*funx_t)(const double *, ...
1
vote
1
answer
40
views
How to pass a pointer to member function to a template function
Here is my simplified code: S.h
class SBase {
...
public:
virtual std::vector<int32_t> getNumbersSet1();
virtual std::vector<int32_t> getNumbersSet2();
}
class SDerived : public ...
4
votes
1
answer
155
views
How to use buffer overflow to modify function pointer value?
I am currently trying to make a code more safe for a cybersecurity exercise. I was asked to make the flag contained in the secret_function() come out. The problem is that I can't modify the code and ...
-1
votes
5
answers
210
views
If statement vs. function pointer (performance) [closed]
Consider the following:
while(running) {
if(logMode == true)
log();
bar();
}
VS
if (logMode == true)
func_ptr = log;
else
func_ptr = noop; //noop is empty function that ...
30
votes
6
answers
5k
views
Why does K&R say that pointers are preferable to arrays as function parameters?
From K&R page 99:
As formal parameters in a function definition,
char s[];
and
char *s;
are equivalent; we prefer the latter because it says more explicitly that the variable is a pointer.
I ...
1
vote
1
answer
53
views
Problems with "qualified-id in declaration before '(' token" and "expected type-specifier" errors [duplicate]
I need to build some template classes in C++17 but I'm getting the following error message:
When I do not define the macro __ALIAS__ I got an error on these lines:
using PF = one<_Return>::...
1
vote
3
answers
168
views
How to avoid lambda capture in loop
Let's say I want to store a collection of function pointers (from lambdas), where each functions body is very similar. Writing everything out by hand gets repetitive and hard to manage, so instead I ...
2
votes
3
answers
189
views
Assign a non-static member function as a same class member variable, which is a function pointer
The example snippet:
#include <iostream>
#include <functional>
#include <vector>
// Simulated callback type
using CallbackType = void(*)(void*, uint32_t);
class DataProcessor{
...
2
votes
1
answer
73
views
Why does this function pointer typedef behave differently when used with const?
#include <stdio.h>
typedef int (*func_t)(int);
int foo(int x) {
return x * 2;
}
int main() {
const func_t ptr = foo; // Works
//const func_t *ptr = &foo; // Fails: why?
...
2
votes
1
answer
97
views
How can I alias std::make_shared?
I have a template wrapper ThreadSafeVar for convenient mutex-locking of variables, and I want to alias std::shared_ptr and std::make_shared so I can do e.g. ThreadSafePtr<int> a = ...
2
votes
2
answers
62
views
Custom memory handling in postGIS
I am currently working on a c++ project leveraging the features of Postgis.
Postgis provides handles to use custom memory allocators for the memory management.
The allocator should be of the signature:...
3
votes
3
answers
127
views
Function pointers point to identical address values? ...sometimes
I have an array of function pointers and I want to assign simple dummy functions.
The first thing that came to my mind was using lambda. That worked pretty well. The only thing that surprised me was ...
2
votes
1
answer
101
views
How to Implement Universal Setter/Getter Functions for Interrupt-Driven Variables in Embedded C?
I had an interrupt functionality implementation in my embedded project with global variables. The interrupt checks PWM signal duty cycle and sets the value of a bool var to true if the value is ...