先创建一个子目录TestStruct,在该目录下,生成一个.h 和两个.cpp文件链接编译,结构如下:
1. 创建出TestStruct目录
2. 在该目录下创建TestStruct.h和TestStruct.cpp,TestStruct1.cpp文件
TestStruct.h
#ifndef LEARN01_TESTSTRUCT_H
#define LEARN01_TESTSTRUCT_H
struct Polar {
int a;
int b;
};
int Add(Polar polar);
#endif //LEARN01_TESTSTRUCT_H
TestStruct.cpp
#include#include "TestStruct.h" using namespace std; int main(){ Polar polar = {1, 2}; cout<<"param1:"< TestStrcut1.cpp
#include "TestStruct.h" int Add(Polar polar) { return polar.a + polar.b; }3. 在TestStruct目录下创建CMakeList.txt文件
include_directories(.) add_executable(TestStruct TestStruct.cpp TestStruct1 TestStruct1.cpp)4.在项目主目录下的CMakeList.txt文件中添加子目录
add_subdirectory(TestStruct) add_executable(Learn01 main.cpp)5. 重新reload Make list
6. 编译执行
end~



