C++ Supplementary

头文件

1
2
3
4
5
6
7
8
9
10
11
12
13
// MyHeader.h
#ifndef CLIONTEST_MY_HEADER_H
#define CLIONTEST_MY_HEADER_H

#include <iostream>

using namespace std;

extern int x;

void f();

#endif

aux.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// aux.cpp
#include "MyHeader.h"

void f() {
cout << "x is " << x << endl;
}

/*
* main.o ------------
* int x;
* int main();
*
* aux.o --------------
* extern int x;
* void f(); ---> uses x
*/

###main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// main.cpp
#include <iostream>

using namespace std;

int main() {
cout << "this is out" << endl;
}

/*
* stdin +-----+ stdout
* ===========->| cpp |===========->
* +-----+
*
* I/O: In/Out
*/