随笔分类 - 【02】C++
摘要:设计模式之PIMPL模式 参考资料 1. 设计模式之PIMPL模式
阅读全文
摘要:调试方法 用 c++filt 还原符号名: echo "_ZN5hf3fsfuseRC..." | c++filt 这样能看到它到底是 hf3fs::fuse::RC::something,还是一个全局对象。 然后你就能判断: 如果它是一个类方法 → 确认实现文件是否编进了 .so。 如果它是个全局
阅读全文
摘要:C++中只用指针而无需完整类型定义教程 在 C++ 里,如果你只用指针来引用一个类型,而不直接使用这个类型的成员或实例,是可以不需要完整定义该类型的,这叫做前向声明(forward declaration)。 1. 例子: #include <iostream> // 前向声明(不需要包含完整头文件
阅读全文
摘要:成员函数指针 在 C++ 中,类成员指针(pointer-to-member)是指向类的成员(可以是数据成员或成员函数)的指针。它和普通指针不一样,必须通过对象或者对象指针来访问。 数据成员指针声明方式: 类型 类名::*指针名; 示例 #include <iostream> struct MyCl
阅读全文
摘要:成员函数后加&的作用 #include <iostream> #include <utility> struct Arg { int i = 1; int aget() && { std::cout << "in aget &&\n"; return i; } int& aget() & { std
阅读全文
摘要:requires关键字 requires 子句(clause):用于指定模板参数必须满足的约束条件: template<typename T> requires std::integral<T> T add(T a, T b) { return a + b; } 这也可以写成简化形式: templa
阅读全文
摘要:参考资料 1attribute__((packed))详解 2GCC的__attribute__扩展特性
阅读全文
摘要:函数__atomic_compare_exchange_n 1. 函数原型: bool __atomic_compare_exchange_n (type *ptr, type *expected, type desired, bool weak, int success_memorder, int
阅读全文
摘要:定位new表达式 当传入一个指针类型实参时,定位new表达式构造对象但是不分配内存。 new(address) type; new(address) type(initializers); new(address) type[size]; new(address) type[size]{braced
阅读全文
摘要:多重继承(无虚函数覆盖) 下面,再让我们来看看多重继承中的情况,假设有下面这样一个类的继承关系。注意:子类并没有覆盖父类的函数。 class Base1 { public: virtual void f() { cout << "Base1::f" << endl; } //虚函数定义 virtua
阅读全文
摘要:std::shared_ptr 下图显示了指向一个内存位置的几个 shared_ptr 实例: 看上面的例子,使用 std::shared_ptr 时,会涉及两次内存分配:一次分配共享资源对象;一次分配控制块。C++ 标准库提供了 std::make_shared 函数来创建一个 shared_pt
阅读全文
摘要:vscode安装插件 #include <algorithm> #include <iostream> #include <string_view> #include <tuple> #include <type_traits> namespace reflection { template <cl
阅读全文
摘要:clang安装 安装依赖包: sudo dnf groupinstall "Development Tools" sudo dnf install cmake ninja-build python3 gcc-c++ 下载clang进行编译安装: # 克隆 LLVM 项目 git clone http
阅读全文
摘要:ceph关于make编译打包制作 find ceph-18.2.2/ -name .gitignore | sed -e "p;s/.gitignore/.gitignore.sunbin/" | xargs -n2 mv git add . git commit --amend find ceph
阅读全文
摘要:协程coroutine #include <coroutine> #include <iostream> using namespace std; struct CoRet { struct promise_type { suspend_never initial_suspend() { retur
阅读全文
摘要:stream使用xshell连接报错 Xshell连接时提示:SSH服务拒绝了密码。请再试一次。 解决方法: vim /etc/ssh/sshd_config PermitRootLogin yes yum 安装报错: # yum install yum-utils Loaded plugins:
阅读全文
摘要:priority_queue 优先队列 大根堆(降序) 构造一个空的优先队列(此队列默认为大根堆) priority_queue<int> big_heap; 另一种构造大根堆的方法: priority_queue<int, vector<int>, less<int>> big_heap; 小根堆
阅读全文
摘要:调用基类的虚函数 代码实现: #include <iostream> class Base { public: virtual void f() { std::cout << "Base::base()" << std::endl; } }; class Test : public Base { p
阅读全文
摘要:centos8 stream仓库配置 默认仓库: [root@centos8-stream yum.repos.d]# ll total 48 -rw-r--r--. 1 root root 713 Mar 28 2022 CentOS-Stream-AppStream.repo -rw-r--r-
阅读全文

浙公网安备 33010602011771号