随笔分类 -  c++

摘要:shift + alt 点击多个位置可以在多个位置添加 阅读全文
posted @ 2020-06-19 17:39 MoonXu 阅读(176) 评论(0) 推荐(0) 编辑
摘要:https://blog.csdn.net/DlMmU/article/details/104129662 阅读全文
posted @ 2020-06-02 02:28 MoonXu 阅读(513) 评论(0) 推荐(0) 编辑
摘要:bind()是一个函数模板,它的原理是根据已有的模板,生成一个函数,但是由于bind()不知道生成的函数执行的时候,传递进来的参数是否还有效。所以它选择参数值传递而不是引用传递。如果想引用传递,std::ref和std::cref就派上用场了。 #include <functional>#inclu 阅读全文
posted @ 2020-04-07 18:51 MoonXu 阅读(541) 评论(0) 推荐(0) 编辑
摘要:#include <numeric> /home/xpy/1.cpp adjacent_difference()//计算邻差或自定义的操作 partial_sum()//计算前n项和或自定义的操作(如:前n项阶乘) accumulate()//计算前n项和或自定义的操作 inner_product( 阅读全文
posted @ 2020-04-07 11:07 MoonXu 阅读(127) 评论(0) 推荐(0) 编辑
摘要:1. 继承是动多态 2.模板是静多态(ploy.cpp ploy .hpp) ploy.hpp #include <cstdlib>#include <vector>#include <iostream>class Coord { private: int x, y; public: Coord ( 阅读全文
posted @ 2020-03-30 13:22 MoonXu 阅读(160) 评论(0) 推荐(0) 编辑
摘要:print.hpp #ifndef __LINK_HPP#define __LINK_HPP#include <iostream>#include <typeinfo>template<typename T>void print(T const&);#include "print.cpp"templ 阅读全文
posted @ 2020-03-20 14:21 MoonXu 阅读(123) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <string>#include <typeinfo> #define HH 1 #ifdef HHtemplate<typename T>inline T const& max(T const& a, T const& b){ return 阅读全文
posted @ 2020-03-18 18:03 MoonXu 阅读(653) 评论(0) 推荐(0) 编辑
摘要:模板如果用内建类型初始化,怎么保证变量得到合适的初始化? template<typename T> void foo() { T x;//不能初始化 } 应该这样 template<typename T> void foo() { T x = T();//合适的初始化 } 同样对于类模板 templ 阅读全文
posted @ 2020-03-18 14:28 MoonXu 阅读(162) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <deque>#include <stdexcept>#include <memory>#include <vector>template<typename T, template<typename ELEM, typename = std:: 阅读全文
posted @ 2020-03-18 14:04 MoonXu 阅读(164) 评论(0) 推荐(0) 编辑
摘要:#include <string>#include <iostream>#include <stdexcept> template<typename T, int MAXSIZE>//template<typename T = int, int MAXSIZE = 100>//可以指定默认值!!!c 阅读全文
posted @ 2020-03-12 20:43 MoonXu 阅读(219) 评论(0) 推荐(0) 编辑
摘要:http://www.josuttis.com/tmplbook/toc.html 阅读全文
posted @ 2020-03-09 13:51 MoonXu 阅读(124) 评论(0) 推荐(0) 编辑
摘要:1. 特化类模板的意义:通过特化类模板可以优化基于某种特定类型的实现, 或者克服某钟特定类型在实例化类模板时所出现的不足。 2. 如果要特化一个类模板,还要特化盖类模板的所有成员函数。虽然可以只特化某个成员函数, 但是这样没有特化整个类,也就没有特化整个类模板。 阅读全文
posted @ 2020-03-09 13:42 MoonXu 阅读(217) 评论(0) 推荐(0) 编辑
摘要:1. 类模板中要自己实现拷贝构造和赋值构造函数的话,应该这样编写 template<typename T> calss Stack { ... Stack(Stack<T> const&);//使用类型时,只用Stack。后边参数使用类的类型要加上模板参数T Stack<T> &operator=( 阅读全文
posted @ 2020-03-09 09:30 MoonXu 阅读(175) 评论(0) 推荐(0) 编辑
摘要:1.当使用函数模板并且引起模板实例化的时候,编译器需要查看模板的定义 2.template<typename T1, typename T2>//实参演绎 inline T1 max(T1 const& a, T2 const& b)//注意函数模板的返回类型只能是T1,不能是T1&,因为有可能返回 阅读全文
posted @ 2020-03-05 01:31 MoonXu 阅读(176) 评论(0) 推荐(0) 编辑
摘要:template<typename T> inline T const& max(T const& a,T const& b) max(4, 7);//ok max(4 , 7.1);//error 解决办法: 1. max(static_cast<double>(4), 7.1); 2.max<d 阅读全文
posted @ 2020-02-02 04:55 MoonXu 阅读(83) 评论(0) 推荐(0) 编辑
摘要:// from c++11 standardnamespace std { template <class T, T v> struct integral_constant { static constexpr T value = v; typedef T value_type; typedef i 阅读全文
posted @ 2020-01-17 13:38 MoonXu 阅读(661) 评论(0) 推荐(0) 编辑
摘要:当一个数据类型满足了”平凡的定义“和”标准布局“,我们则认为它是一个POD数据,非静态成员都是”平凡的“ 1.平凡的 2.平凡的 3.非静态成员“平凡的” 阅读全文
posted @ 2020-01-17 11:43 MoonXu 阅读(516) 评论(0) 推荐(0) 编辑
摘要:void swap (string& x, string& y); #include <iostream>#include <string.h> using namespace std; int main(){ string buyer("money"); string seller("goods" 阅读全文
posted @ 2020-01-17 09:22 MoonXu 阅读(334) 评论(0) 推荐(0) 编辑
摘要:(1) istream& getline (istream& is, string& str, char delim); istream& getline (istream&& is, string& str, char delim); (2) istream& getline (istream& 阅读全文
posted @ 2020-01-17 09:15 MoonXu 阅读(138) 评论(0) 推荐(0) 编辑
摘要:void push_back (char c);//在string的结尾放置一个字符 #include <iostream>#include <string> using namespace std; int main(){ string str("hello world"); str.push_b 阅读全文
posted @ 2020-01-10 20:19 MoonXu 阅读(1056) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示