摘要:
#include // overloading "operator == " inside class // == 是二元操作符 ////////////////////////////////////////////////////////// class Rectangle { public: Rectangle(int w, int h) : width(w), heig... 阅读全文
摘要:
#include <iostream> #include <thread> #include <mutex> #include <Windows.h> // callback test ///////////////////////////////////////////////////////////// // API part typedef void(__stdcall *CallbackE 阅读全文
摘要:
// traits 的应用 /////////////////////////////////////////// // traits template <typename T> class sigmaTraits {}; // 特化 template <> class sigmaTraits<char> { public: typedef int returnType; }; template 阅读全文
摘要:
const 修饰的成员函数 表示 不会修改class中的成员变量。 const 和 非-const 的成员函数同事存在时, 用户定义 const 类对象,调用 const 成员函数; 定义 非-const 类对象,调用 非-const 成员函数。 加上 const 的理由: 比如 string 中的 阅读全文
摘要:
#include // 偏特化的模板不会自己添加构造函数 ctor 和 析构函数 dtor #if 1 // P1 template class Stack { public: Stack() { std::cout class Stack { public: Stack() { std::cout class Stack { public: Stack() { std::... 阅读全文
摘要:
参见:https://en.cppreference.com/w/cpp/algorithm/find 查找指定字符/数字等。 阅读全文
摘要:
参见:https://en.cppreference.com/w/cpp/algorithm/find std::npos 表示 size_t 的最大值,常用于对查找结果成功与否的判断。 阅读全文
摘要:
参见:https://zh.cppreference.com/w/cpp/algorithm/remove 使用 erase 和 remove 配合。 输出结果是: Textwithsomespaces 阅读全文
摘要:
参见:https://zh.cppreference.com/w/cpp/algorithm/remove std::remove 不会改变输入vector / string 的长度。其过程,相当于去除指定的字符(以string为例),剩余字符往前靠。后面的和原始字符保持一致。详见示例程序结果 输出 阅读全文
摘要:
声明和实现在一个文件中: 声明和实现分开在h和cpp文件中: 潜在问题是,仅仅按照普通class的方式分开,在编译的时候,会报 link2019 错误。原因是在编译实例化模板类的文件时,模板类只有声明文件(h)被链接,其实现文件(cpp里面的部分)找不到。 解决办法: * 1 在实例化模板类的文中开 阅读全文