Skip to content

Instantly share code, notes, and snippets.

@mcpherson mcpherson/statmem.cc
Created Mar 27, 2016

Embed
What would you like to do?
Test static pointer to instance member (for use in callback function)
// Test static pointer to object member from callbacks
// g++ -std=c++11 -g -O3 statmem.cc -o statmem
#include <iostream>
class Test;
static Test *bug;
class Test {
public:
int val;
static void ccback(void) {
std::cout << bug->val << std::endl;
}
};
void cback(void) {
std::cout << bug->val << std::endl;
}
int main() {
Test test;
test.val = 10;
bug = &test;
Test::ccback();
cback();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.