Box
Box

C++ Header File

  • *.h file

    • include
      • state variable(header file can define variable, but should be do it)
      • state class / function / templete
      • const / extern
      • inline function
    • exclude
      • using namespace std; or namespace xxx {}, should be used std::cout
      • define anything
  • hello.hpp

1
2
3
4
5
6
#ifndef HELLO_H
#define HELLO_H

void hello();

#endif // HELLO_H
  • hello.cpp
1
2
3
4
5
#include <iostream>

void hello() {
std::cout << "hello" << std::endl;
}
  • main.cpp
1
2
3
4
5
#include "hello.hpp"

int main() {
hello();
}
  • bash
1
2
3
>> g++ -std=c++11 main.cpp hello.cpp
>> ./a.out
hello
Supporting
Scan, Support Daidai
  • WeChat scan
  • Alipay scan