C/C++
文章平均质量分 63
C和C++的语言特性和基础
哲米
深挖程序世界的各种疑难杂症
展开
-
C++ 代码阅读 - 宏
C++ 代码宏原创 2022-07-17 08:59:05 · 393 阅读 · 0 评论 -
Linux Perf对进程进程CPU和内存分析
Linux 查看内存问题原创 2022-06-13 14:56:34 · 2543 阅读 · 0 评论 -
C++ 11 并发编程
Bjarne Stroustrup's Homepagehttps://www.stroustrup.com/与 C++11 多线程相关的头文件C++11 新标准中引入了四个头文件来支持多线程编程,他们分别是<atomic> ,<thread>,<mutex>,<condition_variable>和<future>。<atomic>:该头文主要声明了两个类, std::atomic 和 std::atomic_flag,原创 2022-05-23 17:56:33 · 500 阅读 · 0 评论 -
C++工具库
1.fmtlib/fmt:is an open-source formatting library providing a fast and safe alternative to C stdio and C++ iostreams原创 2021-04-01 14:37:21 · 176 阅读 · 0 评论 -
Linux SIGNAL
#include <machine/signal.h> /* sigcontext; codes for SIGILL, SIGFPE */#define SIGHUP 1 /* hangup */#define SIGINT 2 /* interrupt */#define SIGQUIT 3 /* quit */#define SIGILL 4 /* illegal instruction (not reset whe.原创 2021-03-27 15:38:54 · 95 阅读 · 0 评论 -
高效编程100条
1._n&7 在功能上等价于 _n%8, 但是位操作更快。原创 2020-11-14 11:37:42 · 111 阅读 · 0 评论 -
C++ 基础
1. 检查编译器版本#include <iostream>using namespace std;int main() { cout << __cplusplus <<endl;#if __cplusplus >= 201103L #error __cplusplus >= 201103L#elif __cplusplus <= 199711L #error __cplusplus <= 199711L..原创 2020-07-29 11:28:46 · 450 阅读 · 0 评论 -
C++ 编程规范
原创 2020-07-23 23:33:15 · 104 阅读 · 0 评论 -
C++11常用特性总结
关键字及新语法auto关键字及用法auto并没有让C++成为弱类型语言,也没有弱化变量什么,只是使用auto的时候,编译器根据上下文情况,确定auto变量的真正类型。 auto作为函数返回值时,只能用于定义函数,不能用于声明函数。nullptr关键字及用法class Test{public: void TestWork(int index) { std::cout << "TestWork 1" << std::endl;原创 2020-07-21 23:50:33 · 634 阅读 · 1 评论 -
C++设计模式之单例模式
1.众所周知的单例在一般书籍中或者大家比较是熟知的单例模式是下面这样:class singleton {private: singleton() {} static singleton *p;public: static singleton *instance();};singleton *singleton::p = nullptr;singleton* singleton::instance() { if (p == nullptr)转载 2020-07-21 18:09:49 · 212 阅读 · 0 评论 -
C++智能指针
1. 智能指针的定义智能指针就是一个类,这个类的构造函数中传入一个普通指针,析构函数中释放传入的指针。智能指针的类都是栈上的对象,所以当函数(或程序)结束时会自动被释放。智能指针利用了RAII(资源获取即初始化)的技术,对普通指针进行封装,使得其行为像一个指针,但其实是一个对象。把资源放进对象内,用资源来管理对象,便是 C++ 编程中最重要的编程技法之一,即 RAII ,它是 "Resource Acquisition Is Initialization" 的首字母缩写。智能指针的作用:方便堆内原创 2020-07-16 23:07:21 · 5701 阅读 · 1 评论 -
C++中闭包的简单实现
这个问题的起源是想把成员函数封装为回调函数,众所周知一个比较好的选择是tr1里的function和bind。function对不同类型的函数指针进行统一的封装。例如:int foo() {...}std::tr1::function<int ()> bar = f;bar();如果函数带参数或者是成员函数,使用bind可以实现一个闭包的作用,将对象本身、参数都封装进来,返回一个function对象。例如:struct X { int foo(int data)转载 2020-07-10 15:03:42 · 2031 阅读 · 0 评论 -
C++ STL
setvectorstackqueuelistmap - 关联数组typedef pair<const Key, T> value_type其中key 是 const的,即不可以改变map中的keymap的插入(unordered_map(hash), map(红黑树))map<int,string> mp;mp.insert(m...原创 2019-11-08 11:53:25 · 517 阅读 · 0 评论 -
Safer Typecasting Using ANSI C++ Typecasts
static_cast<type>(expr)for converting between related typesconst_cast<type>exprfor casting awayconstorvolatiledynamic_cast<type>(expr)for safe navigation through an inheritance h...转载 2020-04-07 21:11:18 · 150 阅读 · 0 评论