Skip to content

Instantly share code, notes, and snippets.

@aipi
Created January 27, 2018 14:47
Show Gist options
  • Save aipi/1ff8982534ddbdb7e71fe2b7dfbac95e to your computer and use it in GitHub Desktop.
Save aipi/1ff8982534ddbdb7e71fe2b7dfbac95e to your computer and use it in GitHub Desktop.
Just enjoying callbacks
#include <iostream>
using namespace std;
void printall(char *xpto){
for(int i=0; i < 3; i++){
cout << *(xpto+i);
}
cout << "\n";
}
void changeall(char *xpto){
for(int i=0; i < 3; i++){
*(xpto+i) = '.';
}
}
void func(void (*wrapper)(char *), char *any){
(*wrapper)(any);
}
int main(){
char c[] = {'a', 's', 'r'};
func(printall, c);
func(changeall, c);
func(printall, c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment