随笔分类 - C++
摘要:静态库的生成 代码 add.h #ifndef _ADD_H_ #define _ADD_H_ int add(int a,int b); #endif add.cpp #include<iostream> #include"add.h" int add(int a,int b){ return a
阅读全文
摘要:概念介绍 try...catch 异常捕获,当程序出一个错误时,可以进入错误处理函数,而不同退出,其中 try statement 中是正常的代码块 catch 是当出现一个错误时,会进入该模块进行错误处理。如遇到除 0 错误,段溢出错误 throw 是抛出异常,这个异常不一定错误,只要是认为是有误
阅读全文
摘要:参考 std::string #include<iostream> #include<string> using namespace std; int main() { string str; string base = "The quick brown fox jumps over a lazy
阅读全文
摘要:https://www.cnblogs.com/poissonnotes/p/8444886.html 命名 目录命名 名词短语 -- 小蛇型:全小写字母 + 下划线 名字空间 名次短语 -- 小蛇型:全小写字母 + 下划线 文件命名 名词短语 -- 大驼峰:每个首字母大写 + 继承类名 类和类型
阅读全文
摘要:C++中,如果进行二进制转换 #include<iostream> #include<bitset> using namespace std; #define unsigned int uint32_t void transferRadix(int n){ cout << "hex: " << st
阅读全文
摘要:头文件:<functional> 定义: template< class R, class... Args > class function<R(Args...)>; std::functional 是一个类模板,它是一个通用的多态函数包装器。std::funcion 的实例可以存储、拷贝、和引用任
阅读全文
摘要:operator 是 C++ 一个重载操作符的关键字,但是 operator 除了可以重载操作符以外,还可以用做对两个不同类的转换。 具体使用如下: #include<iostream> using namespace std; struct X { X(){ num = 10; } // impl
阅读全文
摘要:翻译:https://en.cppreference.com/w/cpp/algorithm/copy 定义在头文件 <algorithm> 函数声明 template< class InputIt, class OutputIt > OutputIt copy( InputIt first, In
阅读全文
摘要:翻译:https://en.cppreference.com/w/cpp/algorithm/fill_n 定义在头文件<algorithm> 函数声明: template< class OutputIt, class Size, class T > void fill_n( OutputIt fi
阅读全文
摘要:翻译:https://en.cppreference.com/w/cpp/iterator/back_inserter 定义在头文件 <iterator> 函数声明如下: template< class Container > std::back_insert_iterator<Container>
阅读全文
摘要:使用组合的方式实现tuple的功能 #include<iostream> using namespace std; template<typename... Values> class tup; template<> class tup<>{}; // to realize function of
阅读全文
摘要:利用递归继承的方式实现tuple #include<iostream> using namespace std; template<typename... Values> class tuples; template<> class tuples<>{}; template<typename Hea
阅读全文
摘要:如果最后一个元素的处理方式不同于前面的,可以使用以下递归调用 #include<iostream> #include<tuple> #include<bitset> using namespace std; template <int IDX, int MAX, typename... Args>
阅读全文
摘要:循环调用的 max #include<iostream> using namespace std; int maximum(int n) { return n; } template <typename... Args> int maximum(int n, Args... args) { retu
阅读全文
摘要:迭代器的递归调用实现max功能,max函数接受任意参数 #include<iostream> using namespace std; struct _Iter_less_iter { template<typename _Iterator1 , typename _Iterator2> bool
阅读全文
摘要:使用可变参数模板重写print #include<iostream> #include<bitset> using namespace std; void printX() { } template<typename T, typename... Types> void printX(const T
阅读全文
摘要:1. 为什么要使用lambda + 就地匿名的定义一个目标函数或者函数对象,不需要额外的再写一个命名函数或者函数对象,以更直接的方式去写函数,可以调高程序的可读性和可维护性。 + 简洁:不要额外的的再写一个函数或者函数对象,避免了代码膨胀或者功能分散。 + 在需要的时间或者地点实现功能闭包,是程序更
阅读全文
摘要:C++ shared_ptr 使用总结: class Color { public: Color(uint32_t _red, uint32_t _yellow, uint32_t _green) : mRed(_red) , mYellow(_yellow) , mGreen(_green) {
阅读全文
摘要:以 32 bit system 为例: signed char 8 bit 0000 0000 有符号类型,需要最高位表示符号,所以一共 7 bit 表示大小 signed char 能表示的范围为 -2^7 ~ 2^7-1 unsigned char 表示的范围为 0 ~ 2^8-1 依次类推 s
阅读全文
摘要:在C/C++中,mian函数的返回值可以在环境变量中获取到。 echo $? 原因:谁调取的C++程序,谁可以获取到该程序的返回值。 如果是java调取C++函数,那么java也可以获取到对应的main函数返回值数据。 如果是在linux下允许,那么默认是当前系统调用的该程序,那么mian函数的返回
阅读全文