摘要:右值和右值引用 ref https://en.cppreference.com/w/cpp/language/reference https://www.cnblogs.com/KillerAery/p/12802771.html 左值和右值 左值:表达式结束之后仍然存在的持久对象; 右值:表达式结
阅读全文
摘要:stdarg Question How does va_arg (and so on) implemented? What will happen if you call printf("%d", char)? Answer Question 1: It is not implemented as
阅读全文
摘要:# 虚函数 ## 虚函数表 ### 示例 ```c++ // code of virtual function // filename: test.cpp #include class A { public: virtual ~A() {} void draw(){draw_imp();} prot
阅读全文
摘要:# 函数对象 ## 定义 定义了operator()的对象就是函数对象。 ## 函数的封装 可以使用std::function对函数(指向函数的指针)、lambda表达式、bind表达式、函数对象、指向成员函数的指针、指向成员变量的指针; ### 简单示例 ```c++ #include #incl
阅读全文
摘要:# 大量创建对象的性能 注:试验中,均统一开启 O3 优化。试验均在同一系统上进行。 ## 背景 在构建一种通用图片对象时,一种可能的实现是将每个像素作为一个对象处理。 以2560*1440为例,约
3.6×106像素,因此在构建图片时,需要创建大量像素对象。 本文讨论C++下创建大
阅读全文
摘要:# 智能指针 ## std::auto_ptr ```c++ #include #include int main() { std::auto_ptr ptr(new int); std::auto_ptr ptr1 = ptr; std::cout cfg) { cfg_ = cfg; } std
阅读全文
摘要:# 默认函数 ## 关于 当用户没有定义时,C++ 会为类对象自动生成一些成员函数,这些函数称为默认函数。 默认函数包括(仅列举重要的默认函数): - 默认构造、拷贝构造、移动构造、析构 - 拷贝赋值 - 移动赋值 其形式如: ```c++ class Obj { public: Obj(); Ob
阅读全文
摘要:# 类型转换 ## 一些问题 ### 表达式计算并传参时的类型转换问题 例子如下: ```c++ #include #include int main() { uint8_t a = 254; uint8_t b = 2; uint32_t c = a + b; printf("c=%d\n", (
阅读全文
摘要:# 大量创建对象的性能 注:试验中,均统一开启 O3 优化。试验均在同一系统上进行。 ## 背景 在构建一种通用图片对象时,一种可能的实现是将每个像素作为一个对象处理。 以2560*1440为例,约
3.6×106像素,因此在构建图片时,需要创建大量像素对象。 本文讨论C++下创建大
阅读全文