课程代码仓库初始化:Part1 (144) + Part3 (29) 全量生成与验证

把川大 wiki「02.Qt方向」课程代码整理为 CMake 管理的可编译运行项目。

Part1 C/C++ 强化 (p01/, 144 目标, host gcc/g++ 构建, 全绿):
- 修复全部编译失败:补 <cstring>/<fstream>/<iomanip>/<vector> 等缺失头
  (common_fix + infer_stl_includes 自动检测注入)、修正 pause() 壳注入
  (改检测已转换后的 pause 调用)、namespace 提升出函数体、const 成员函数
  正确性、dedupe 不再破坏函数重载集、K&R 隐式 int / 动态异常规范等
  C++17 移除特性的可编译等价改写。
- 目录采用深缩写 p01/ch04/s03/ (原 part1_cpp/ch04_class_object/03_ctor_dtor)。

Part3 Qt 桌面 (p03/, 29 目标, 隔离 Qt 5.14.2 构建, 全绿):
- gen_part3.py: Qt 外壳模板 (main+QApplication+show, QTimer 自动退出便于
  offscreen 验证)、AUTOMOC + .moc include、rewrite_* 处理散文混入/重载/
  资源依赖、生成占位 png/gif + .qrc + rundata 样例数据。
- 修正 QLable 笔误、全角分号、.→->、Windows 路径、QApplication 阻塞事件
  循环改为 QCoreApplication 等。

任务1 概念/版本验证:
- tools/std_probe.py: 跨 -std= 编译探针 (--pedantic-errors 让已废除特性硬失败)。
- tools/demo_versions/: K&R 隐式 int、三目左值、void* 转换、enum 赋整、
  const 经指针、动态异常规范 共 6 个跨版本演示。
- docs/VERSION_NOTES.md: 每条「原文说法→C17/C++17 是否成立→何版本成立→已验证」。

文档: 顶层 README、docs/SOURCE_PAGES.md (页面→目录映射)、
docs/ERRATA.md (Part1 修正)、docs/ERRATA_part3.md (Part3 修正)。
另修复 tools/run.sh / run_qt.sh 的 ${1:?...} 引号语法 bug。

隔离 Qt 验证: ldd 0 系统 Qt 引用; 173/173 目标全绿; p03 offscreen 运行通过。
This commit is contained in:
张宗平
2026-06-30 14:16:55 +08:00
commit 13b3ebbe14
287 changed files with 16532 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
# Auto-generated by tools/gen_part1.py — do not edit by hand.
# 章节:p01/ch04/s04
add_executable(p1c04_04_01 member_storage.cpp)
set_target_properties(p1c04_04_01 PROPERTIES C_STANDARD 17 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF)
set_target_properties(p1c04_04_01 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
target_compile_options(p1c04_04_01 PRIVATE -Wall -Wextra)
add_executable(p1c04_04_02 this_pointer.cpp)
set_target_properties(p1c04_04_02 PROPERTIES C_STANDARD 17 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF)
set_target_properties(p1c04_04_02 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
target_compile_options(p1c04_04_02 PRIVATE -Wall -Wextra)
add_executable(p1c04_04_03 const_member_function.cpp)
set_target_properties(p1c04_04_03 PROPERTIES C_STANDARD 17 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF)
set_target_properties(p1c04_04_03 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
target_compile_options(p1c04_04_03 PRIVATE -Wall -Wextra)
add_executable(p1c04_04_04 const_object.cpp)
set_target_properties(p1c04_04_04 PROPERTIES C_STANDARD 17 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF)
set_target_properties(p1c04_04_04 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
target_compile_options(p1c04_04_04 PRIVATE -Wall -Wextra)
add_custom_target(all_p01_ch04_s04 DEPENDS p1c04_04_01 p1c04_04_02 p1c04_04_03 p1c04_04_04)
+46
View File
@@ -0,0 +1,46 @@
// ============================================================================
// p1c04_04_03 — 4.4.2.3 const修饰成员函数
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
// 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用
// // --- 原文片段 [pageId:blockIdx] --- 标注出处。
// 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。
// ============================================================================
#include <iostream>
using namespace std;
#include <cstdio>
static inline void pause() { printf("按回车键继续..."); (void)getchar(); }
// --- 原文片段 [58954456:2] 4.4.2.3 const修饰成员函数 ---
//const修饰成员函数
class Person{
public:
Person(){
this->mAge = 0;
this->mID = 0;
}
//在函数括号后面加上const,修饰成员变量不可修改,除了mutable变量
void sonmeOperate() const{
//this->mAge = 200; //mAge不可修改
this->mID = 10;
}
void ShowPerson(){
cout << "ID:" << mID << " mAge:" << mAge << endl;
}
private:
int mAge;
mutable int mID;
};
int main(){
Person person;
person.sonmeOperate();
person.ShowPerson();
pause();
return EXIT_SUCCESS;
}
// --- main ---
+48
View File
@@ -0,0 +1,48 @@
// ============================================================================
// p1c04_04_04 — 4.4.2.4 const修饰对象(常对象)
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
// 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用
// // --- 原文片段 [pageId:blockIdx] --- 标注出处。
// 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。
// ============================================================================
#include <iostream>
using namespace std;
// --- 原文片段 [58954456:3] 4.4.2.4 const修饰对象(常对象) ---
class Person{
public:
Person(){
this->mAge = 0;
this->mID = 0;
}
void ChangePerson() const{
//mAge = 100; // 非法:const 成员函数内不能修改非 mutable 成员
mID = 100; // 合法:mID 被 mutable 修饰,const 函数内可改
}
void ShowPerson(){
this->mAge = 1000;
cout << "ID:" << this->mID << " Age:" << this->mAge << endl;
}
public:
int mAge;
mutable int mID;
};
void test(){
const Person person;
//1. 可访问数据成员
cout << "Age:" << person.mAge << endl;
//person.mAge = 300; //不可修改
person.mID = 1001; //但是可以修改mutable修饰的成员变量
//2. 只能访问const修饰的函数
//person.ShowPerson();
person.ChangePerson();
}
// --- main ---
int main() {
test();
return 0;
}
+65
View File
@@ -0,0 +1,65 @@
// ============================================================================
// p1c04_04_01 — 4.4.1 成员变量和函数的存储
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
// 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用
// // --- 原文片段 [pageId:blockIdx] --- 标注出处。
// 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。
// ============================================================================
#include <iostream>
using namespace std;
// --- 原文片段 [58954456:0] 4.4.1 成员变量和函数的存储 ---
class MyClass01{
public:
int mA;
};
class MyClass02{
public:
int mA;
static int sB;
};
class MyClass03{
public:
void printMyClass_1(){
cout << "hello world!" << endl;
}
public:
int mA;
static int sB;
};
class MyClass04{
public:
void printMyClass_1(){
cout << "hello world!" << endl;
}
static void ShowMyClass(){
cout << "hello world" << endl;
}
public:
int mA;
static int sB;
};
int main(){
MyClass01 mclass01;
MyClass02 mclass02;
MyClass03 mclass03;
MyClass04 mclass04;
cout << "MyClass01:" << sizeof(mclass01) << endl; //4
//静态数据成员并不保存在类对象中
cout << "MyClass02:" << sizeof(mclass02) << endl; //4
//非静态成员函数不保存在类对象中
cout << "MyClass03:" << sizeof(mclass03) << endl; //4
//静态成员函数也不保存在类对象中
cout << "MyClass04:" << sizeof(mclass04) << endl; //4
return EXIT_SUCCESS;
}
// --- main ---
+71
View File
@@ -0,0 +1,71 @@
// ============================================================================
// p1c04_04_02 — 4.4.2.2 this指针的使用
// 来源:川大 C++/LinuxC wiki「02.Qt方向」
// 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用
// // --- 原文片段 [pageId:blockIdx] --- 标注出处。
// 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。
// ============================================================================
#include <iostream>
using namespace std;
#include <cstdio>
static inline void pause() { printf("按回车键继续..."); (void)getchar(); }
// --- 原文片段 [58954456:1] 4.4.2.2 this指针的使用 ---
class Person{
public:
//1. 当形参名和成员变量名一样时,this指针可用来区分
Person(string name,int age){
//name = name;
//age = age; //输出错误
this->name = name;
this->age = age;
}
//2. 返回对象本身的引用
//重载赋值操作符
//其实也是两个参数,其中隐藏了一个this指针
Person PersonPlusPerson(Person& person){
string newname = this->name + person.name;
int newage = this->age + person.age;
Person newperson(newname, newage);
return newperson;
}
void ShowPerson(){
cout << "Name:" << name << " Age:" << age << endl;
}
public:
string name;
int age;
};
//3. 成员函数和全局函数(Perosn对象相加)
Person PersonPlusPerson(Person& p1,Person& p2){
string newname = p1.name + p2.name;
int newage = p1.age + p2.age;
Person newperson(newname,newage);
return newperson;
}
int main(){
Person person("John",100);
person.ShowPerson();
cout << "---------" << endl;
Person person1("John",20);
Person person2("001", 10);
//1.全局函数实现两个对象相加
Person person3 = PersonPlusPerson(person1, person2);
person1.ShowPerson();
person2.ShowPerson();
person3.ShowPerson();
//2. 成员函数实现两个对象相加
Person person4 = person1.PersonPlusPerson(person2);
person4.ShowPerson();
pause();
return EXIT_SUCCESS;
}
// --- main ---