Skip to content

Instantly share code, notes, and snippets.

@vitonzhangtt
Last active January 5, 2018 03:14
Show Gist options
  • Save vitonzhangtt/adf415bfc258b8ccd26d9a343a34b845 to your computer and use it in GitHub Desktop.
Save vitonzhangtt/adf415bfc258b8ccd26d9a343a34b845 to your computer and use it in GitHub Desktop.
Static variable definition in Header file
#include "TTCounter.h"
#include "TTDislikeCounter.h"
#include "TTLikeCounter.h"
void printTotalCounter() {
printf("total counter: %d", totalCounter);
}
int main(int argc, char *argv[]) {
addDislikeToTotalCounter();
addLikeToTotalCounter();
printTotalCounter();
return 0;
}
// TTCounter.h
static int totalCounter = 0;
#include "TTCounter.h"
void addDislikeToTotalCounter() {
totalCounter++;
}
// TTDislikeCounter.h
void addDislikeToTotalCounter();
#include "TTCounter.h"
void addLikeToTotalCounter() {
totalCounter++;
}
// TTLikeCounter.h
void addLikeToTotalCounter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment