Related
Abruzzo Forte and Gentile This is a newbie question, but I don't understand how it works. Suppose I have the following function void foo(const std::string& v) {
cout << v << endl;
}
and the call in my program below. foo("hi!");
Essentially, I'm passing a
dvrer What is the best practice to avoid UB when passing std::function<void()>in pointers []? Will cls_ptrit always work if the object is not deleted second_on_finish? Here is the current code: void Foo()
{
SomeClass* cls_ptr = GetPointerToClass();
st
dvrer What is the best practice to avoid UB when passing std::function<void()>in pointers []? Will cls_ptrit always work if the object is not deleted second_on_finish? Here is the current code: void Foo()
{
SomeClass* cls_ptr = GetPointerToClass();
st
John Doe I want to pass a function as a parameter and return void *a to another function. Right now I have the following code: MyClass *MyClass::bind(std::function<void*(void *)> fun) {
this->value = fun(this->value);
return this;
}
valueis void *an i
Sephora I'm also having trouble passing void*parameters through functions void*: #include <stdlib.h>
void* hello(void* (*calc)(void *), void* op){
int val = *(int *) op;
int* retval = malloc(sizeof(int));
*retval = calc(val);
return retval;
}
connectionist I have the following function: void PerformAction(void(*pf_action)());
and the following class: class A
{
public:
void DoSomething();
}
I would like to be able to do this: int main()
{
A a;
PerformAction(&(a.DoSomething);
retur
connectionist I have the following function: void PerformAction(void(*pf_action)());
and the following class: class A
{
public:
void DoSomething();
}
I would like to be able to do this: int main()
{
A a;
PerformAction(&(a.DoSomething);
retur
Anthony Monterosa Since template parameters can only have pointers to objects, and lambda literals are not allowed, I've been trying to find a way to capture the lambda and pass it as a std::function. Since the parameter can't be a normal function, I know it h
Anthony Monterosa Since template parameters can only have pointers to objects, and lambda literals are not allowed, I've been trying to find a way to capture the lambda and pass it as a std::function. Since the parameter can't be a normal function, I know it h
Dan Clemenko I have the following C++ code (just an example of a simple problem) #include <iostream>
#include <string>
#include <vector>
double get_first(const std::vector<double>& vec) {
return vec[0];
}
int main()
{
std::vector<double> some_vec = {1,
Offir Pe'er I want to pass to SetTimer function TagContactByMail instead of 2 strings. public void AddTagToContact(string tagName, string contactEmail)
{
SetTimer(tagName, contactEmail);
aTimer.Dispose();
}
Thi
traffic red A callback function with this prototype: void serverAnswer(void *pUserData, int flag);
I need to pass a buffer to this function const uint8_t *bufwith a void parameter . How do I pass the buffer, and how do I access the elements of the buffer in t
Offir Pe'er I want to pass to SetTimer function TagContactByMail instead of 2 strings. public void AddTagToContact(string tagName, string contactEmail)
{
SetTimer(tagName, contactEmail);
aTimer.Dispose();
}
Thi
Kemmer After years of writing Java, I wanted to dive deeper into C++ again. Although I think I can handle it, I don't know if it is handled with the "state of the art". Currently, I'm trying to understand how to handle std::strings that are passed as constant
Kemmer After years of writing Java, I wanted to dive deeper into C++ again. Although I think I can handle it, I don't know if it is handled with the "state of the art". Currently, I'm trying to understand how to handle std::strings that are passed as constant
Risen I'm a little confused about an example in the textbook. After the string is created, it will be created as string type. However, when passing the same string to a function, the function parameter is a const string, not a string. Here is part of the code:
Risen I'm a little confused about an example in the textbook. When creating a string, create it as type string. However, when the same string is passed to the function, the function parameters are const stringand string. Here is part of the code: int main()
{
Risen I'm a little confused about an example in the textbook. After the string is created, it will be created as string type. However, when passing the same string to a function, the function parameter is a const string, not a string. Here is part of the code:
Risen I'm a little confused about an example in the textbook. After the string is created, it will be created as string type. However, when passing the same string to a function, the function parameter is a const string, not a string. Here is part of the code:
Risen I'm a little confused about an example in the textbook. When creating a string, create it as type string. However, when the same string is passed to the function, the function parameters are const stringand string. Here is part of the code: int main()
{
Risen I'm a little confused about an example in the textbook. After the string is created, it will be created as string type. However, when passing the same string to a function, the function parameter is a const string, not a string. Here is part of the code:
Shohreh I have a class that has a public std::functionmember like this: class B
{
public:
B(std::function<void(void)> _func = NULL) : m_function(_func) { }
std::function<void()> m_function;
};
I have a class Xwith member functions SomeFunction: class
Shohreh I have a class that has a public std::functionmember like this: class B
{
public:
B(std::function<void(void)> _func = NULL) : m_function(_func) { }
std::function<void()> m_function;
};
I have a class Xwith member functions SomeFunction: class
Atlas I did the following typedef in a program (C): typedef void* ListElement; typedef int(*CompareListElements)(ListElement, ListElement); I made a function pointer in my code:CompareListElements compareElement Later in the code, I wish to use qsort on the Li
Atlas I did the following typedef in a program (C): typedef void* ListElement; typedef int(*CompareListElements)(ListElement, ListElement); I made a function pointer in my code:CompareListElements compareElement Later in the code, I wish to use qsort on the Li
air traffic control I did the following typedef in a program (C): typedef void* ListElement; typedef int(*CompareListElements)(ListElement, ListElement); I made a function pointer in my code:CompareListElements compareElement Later in the code, I wish to use q
air traffic control I did the following typedef in a program (C): typedef void* ListElement; typedef int(*CompareListElements)(ListElement, ListElement); I made a function pointer in my code:CompareListElements compareElement Later in the code, I wish to use q
Adrian Claire I'm currently trying to store some listeners in a std::vector and call them when needed. I have the following definition in the base class: class A
{
public:
virtual ~A();
typedef std::function< void( const A & ) > Listener;
std::vect
connor449 I am trying to solve an optimization problem in c++ using the NLopt library. The documentation indicates that the input function to be optimized should look like this: double myfunc(const std::vector<double> &x, std::vector<double> &grad, void *my_fu