Skip to content

Instantly share code, notes, and snippets.

@tell
Last active February 18, 2017 15:17
Show Gist options
  • Save tell/0996941b9c6ac07d8ac9b29cddad873e to your computer and use it in GitHub Desktop.
Save tell/0996941b9c6ac07d8ac9b29cddad873e to your computer and use it in GitHub Desktop.
A sample of extern
### https://raw.github.com/github/gitignore/f2ce448f2ba7a092da05482ceca99209127c0884/c++.gitignore
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
#include "a.hpp"
A::A() : a(0), b(a) {}
int A::c = 10;
const int &A::d = A::c;
int N = 100;
#pragma once
struct A {
int a;
const int &b;
static int c;
static const int &d;
A();
};
#include <iostream>
#include "a.hpp"
extern const int N;
using namespace std;
int main() {
A x;
x.a = 1;
cout << x.b << endl;
cout << x.c << endl;
cout << x.d << endl;
x.c = 20;
cout << x.d << endl;
cout << N << endl;
}
CC = $(CXX)
%.out:
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
main.out: b.o a.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment