随笔分类 - C/C++
摘要:10.4.1 C 语言中,间接赋值是指针存在的最大意义 #include "iostream" using namespace std; struct Teacher { char name[64]; int age; }; // 函数参数为 二级指针,做输出 int getTeacher(Teac
阅读全文
摘要:15. 模板(Templates) Reuse source code generic programming use types as parameters in class or function definitions Template functions Template classes 1
阅读全文
摘要:14. 运算符重载 14.1 Overloaded operator Just a function with an operator name! Use the operator keyword as a prefix to name operator *(...) Can be a member
阅读全文
摘要:13. 静态对象 13.1 Static in C++ Two basic meanings: Static storage allocated once at a fixed address Visibility of a name internal linkage Don't use stati
阅读全文
摘要:12 拷贝构造 Create a new object from an existing one For example, when calling a function // Currency as pass-by-value argument void func(Currency p) { co
阅读全文
摘要:11. 多态 11.1 Conversions Public Inheritance should imply substitution If B isa A, you can use a B anywhere an A can be used. 示例: #include <iostream> us
阅读全文
摘要:10. 引用 References are a new data type in C++; Local or global variables For ordinary variables, the initial value is required In parameter lists and m
阅读全文
摘要:9. Const declares a variable to have a constant value Constants are variables Observe(遵守) scoping rules Declared with "const" type modifier 9.1 Compil
阅读全文
摘要:安装 sudo apt-get install build-essential module-assistant sudo apt-get install gcc-multilib g++-multilib 编译 gcc -m32 hello.c 参考资料: gcc 编译 32 位程序
阅读全文
摘要:7. Composition(组合) Composition: construct new object with existing objects. It is the relationship of "has-a". Ways of inclusion: Fully By reference 示
阅读全文
摘要:5. Constructor(构造函数) If a class has a constructor, the compiler automatically calls that constructor at the point an object is created, before client
阅读全文
摘要:4. 成员变量 4.1 Fields, parameters, local variables All three kinds of variable are able to store a value that is appropriate to their defined type. 4.1.1
阅读全文
摘要:3. 自动售票机例子 TicketMachine.h #ifndef TICKETMACHINE_H_ #define TICKETMACHINE_H_ class TicketMachine { public: TicketMachine(); virtual ~TicketMachine();
阅读全文
摘要:1,第一个 C++ 程序 编译方式:g++ main.cpp 1.1 输出 main.cpp #include <iostream> using namespace std; // 输出 int main() { cout << "Hello, World! I am " << 18 << " To
阅读全文
摘要:1,准备工作: CLion 2021.2 Pthreads-Win32(使用迅雷FTP下载地址:ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip) MinGW 2,Pthreads-Win32 配置 在 Wi
阅读全文
摘要:1, 入门程序 创建hello.c文件,并将下方代码粘贴; 使用gcc hello.c -o hello编译该文件; 运行:./hello; #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } 2, 变量 #in
阅读全文
摘要:C++ 文件的后缀 .cc, .cxx, .cpp, .cp, .c 通过命令行编译程序 1. 编写文件 prog1.cc int main() { return 0; } 2. 执行命令: CC prog1.cc 或者: g++ -o prog1 prog1.cc 3. 运行生成的文件 Linux
阅读全文
摘要:1. 打印摄氏度 参考资料: "The C Programming Language" "Exercise 1.9 Replace Continous blanks with a single blank" "K&R Exercise 1 9 (C)"
阅读全文