随笔分类 -  C/C++

摘要:#include <iostream> template <typename... Args> inline void my_print(const char* format, Args... rest) { printf(format, rest...); } int main(int argc, 阅读全文
posted @ 2022-05-21 17:23 邱明成 阅读(40) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> using namespace std; enum Abc { AAA = -1, BBB = 0, CCC = 1 }; class EnumToStringUtil { public: static const char* ConvertAbcToStri 阅读全文
posted @ 2022-03-16 10:20 邱明成 阅读(210) 评论(0) 推荐(0) 编辑
摘要:问题: nm -A -l a.out出现如下信息: 0000000020 r func 说明,这个变量在只读数据段,并且是static的。 如果编译a.out时加上 -O3 发现0000000020 r func没有了 尝试O1,O2,现象类似。 结论:使用gcc的O1,O2,O3优化时,静态变量的 阅读全文
posted @ 2022-03-14 22:59 邱明成 阅读(360) 评论(0) 推荐(0) 编辑
摘要:大量的安全漏洞是由于计算机算术运算的微妙细节引起的, 具体的C语言, 诸如符号数和无符号数之间转换, 算术运算的越界都会导致不可预知的错误和安全漏洞, 具体的案例数不胜数.作为一个系统程序员, 有必要对这些细节有深入的了解. 本篇参考csapp, 主要介绍如何判断算术运算的越界问题.(虽然本篇的代码 阅读全文
posted @ 2022-02-20 15:53 邱明成 阅读(171) 评论(0) 推荐(0) 编辑
摘要:// sleep() 秒级 // usleep() 微秒级 #include <iostream> using namespace std; #include <unistd.h> int main() { while (1) { cout << "hello" << endl; // sleep( 阅读全文
posted @ 2022-01-13 21:37 邱明成 阅读(6545) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <string> using namespace std; class P { public: int id; string name; public: P() { cout << "wu can p gou zao " << endl; } 阅读全文
posted @ 2021-11-08 08:54 邱明成 阅读(119) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <string> using namespace std; class P { public: int id; string name; public: P() { cout << "wu can p gou zao " << endl; } 阅读全文
posted @ 2021-11-08 08:48 邱明成 阅读(165) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <string> using namespace std; class Person { public: int id2 = 202; int id1 = 201; public: Person() = default; // 当使用常量进行 阅读全文
posted @ 2021-11-07 22:37 邱明成 阅读(189) 评论(0) 推荐(0) 编辑
摘要:默认构造函数以下两种写法是等价的// Person(){}Person() = default; // 显示禁用系统为我们自动生成默认构造函数Person() = delete; 阅读全文
posted @ 2021-11-07 22:12 邱明成 阅读(152) 评论(0) 推荐(0) 编辑
摘要:1. 类的静态非常量成员不能在声明的时候进行初始化2. 类的静态成员(属性与函数)在定义的时候不能加static(声明和定义分开时)3. 普通成员属性默认初始值是不确定的,静态成员属性的默认初始值是会给定相应类型的0值5. 普通常量成员属性除了在声明的时候给定初始值外,还可以在构造函数的初始化列表给 阅读全文
posted @ 2021-11-07 22:10 邱明成 阅读(166) 评论(0) 推荐(0) 编辑
摘要:代码1: #include <iostream> using namespace std; class Person { public: int id = 200; //如果这里没有代码id(1000),定义出来的对象的id值为int id = 200;代码初始的值 Person() : id(10 阅读全文
posted @ 2021-11-07 16:15 邱明成 阅读(103) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> using namespace std; class Person { public: int id = 200; string name = "qiumc"; // 在类中声明并定义静态常量字符串数组 // char*改为string类型会报错 // 没有c 阅读全文
posted @ 2021-11-07 15:36 邱明成 阅读(1642) 评论(0) 推荐(1) 编辑
摘要:a1.cpp代码: static int TEST_COMMON = 100; a2.cpp代码: #include <iostream> using namespace std; extern int TEST_COMMON; int main(int argc, char const *argv 阅读全文
posted @ 2021-11-07 14:53 邱明成 阅读(258) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> using namespace std; int& GetStaticVar() { static int a = 100; a++; return a; } int main(int argc, char const* argv[]) { cout << G 阅读全文
posted @ 2021-11-07 14:24 邱明成 阅读(597) 评论(1) 推荐(0) 编辑
摘要:一:知识点: 成员函数末尾增加const1)该函数被称为常量成员函数2)在函数的定义和声明处的末尾都要加const3)该成员函数不能修改类中的任何成员(非mutable修饰的任意成员属性)4)const 类型的类变量,不能调用非常量成员函数5)const和非const类变量,可以调用常量成员函数(c 阅读全文
posted @ 2021-11-07 11:33 邱明成 阅读(190) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <string> using namespace std; class Person { public: int id; string name; public: Person() { this->id = 200; cout << "Non 阅读全文
posted @ 2021-11-07 10:10 邱明成 阅读(170) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> using namespace std; int g_base_num = 1; class Teacher { public: int id; int* studentIds{nullptr}; int count; public: // 构造函数 Teac 阅读全文
posted @ 2021-10-29 21:20 邱明成 阅读(404) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <string> using namespace std; class Array { public: Array() { length = 0; num = NULL; }; Array(int n); int& operator[](in 阅读全文
posted @ 2021-10-29 13:02 邱明成 阅读(59) 评论(0) 推荐(0) 编辑
摘要:C 库函数 - longjmp() C 标准库 - <setjmp.h> 描述 C 库函数 void longjmp(jmp_buf environment, int value) 恢复最近一次调用 setjmp() 宏时保存的环境,jmp_buf 参数的设置是由之前调用 setjmp() 生成的。 阅读全文
posted @ 2021-10-27 16:49 邱明成 阅读(100) 评论(0) 推荐(0) 编辑
摘要:#include <stdlib.h> #include <iostream> #include <string> using namespace std; class Person { public: Person() { id = 0; name = nullptr; cout << "cons 阅读全文
posted @ 2021-10-25 21:14 邱明成 阅读(201) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示