愚人节
100篇
谨以此篇纪念我逝去的半天
include什么
导入头文件(
.h
)和源文件(.cpp
)Note: 只导入 源文件(
.cpp
) 也可以CMakeLists.txt
手动添加
1
2
3
4
5
6
7cmake_minimum_required(VERSION 3.15)
project(HCpp)
set(CMAKE_CXX_STANDARD 11)
add_executable(HCpp main.cpp)
add_executable(ElemType ElemType.cpp ElemType.h)自动添加
1
2
3
4
5
6
7
8
9
10
11
/**
* Author: ${USER_NAME}
* Date: ${DATE}
* TODO:
* Describe:
#if ($ORGANIZATION_NAME && $ORGANIZATION_NAME != "")
* Copyright (c) $YEAR ${ORGANIZATION_NAME}#if (!$ORGANIZATION_NAME.endsWith(".")).#end All rights reserved.
#end
*/
ElemType.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22/**
* Author: Dgimo
* Date: 2020/4/1
* TODO:
* Describe:
*/
class ElemType {
public:
int data;
ElemType();
ElemType(int);
friend std::ostream &operator <<(std::ostream &, const ElemType &);
};ElemType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22/**
* Author: Dgimo
* Date: 2020/4/1
* TODO:
* Describe:
*/
ElemType::ElemType() {
this->data = 0;
}
ElemType::ElemType(int data) {
this->data = data;
}
std::ostream& operator <<(std::ostream &out, const ElemType &e)
{
out << e.data;
return out;
}main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
using namespace std;
int main() {
ElemType e = ElemType(10);
cout << e << endl;
return 0;
}运算符重载:详见 运算符重载