Skip to content

Instantly share code, notes, and snippets.

@RDCH106
Created November 22, 2018 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RDCH106/a696a95da330ebb2b72d8cd252b2ca0f to your computer and use it in GitHub Desktop.
Save RDCH106/a696a95da330ebb2b72d8cd252b2ca0f to your computer and use it in GitHub Desktop.
C++ calback example
#include <iostream>
#include <string>
#include <vector>
// Dll
typedef bool (*PointerToF)(int number);
struct A {
PointerToF m_f;
void setF(PointerToF f) {
m_f = f;
}
bool call() {
return m_f(4);
}
};
// Ejecutable
bool myf(int number) {
std::cout << number << std::endl;
return number != 0;
}
int main()
{
/* Option A */
A a;
a.setF(&myf);
a.call();
/* Option B */
// PointerToF una_f = nullptr;
// una_f = &myf;
// una_f(4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment