学习笔记:几种注入方法
来源:互联网 发布:开淘宝描述店铺怎么写 编辑:程序博客网 时间:2024/05/16 11:18
//member templateclass Integer{public: template <int N> void multiple();private: int i_;};template <> void Integer::multiple<-1>(){ i_=0; }template <> void Integer::multiple<1>(){}template <> void Integer::multiple<2>(){ i_<< 1; }template <> void Integer::multiple<3>(){ i_*=3 ; }void main(){ Integer i; i.multiple<2>(); //ok. and fast. i.multiple<4>(); //compile error}//crtp idiom.template<class H>class Arithmetic{ //interfacepublic: H& operator++() { H* ph = static_cast<H*>(this); ph->inc(1); return *ph; } H& operator+=(int n) { H* ph = static_cast<H*>(this); ph->inc(n); return *ph; } H operator++(int n) { H* ph = static_cast<H*>(this); H tmp = *ph; ph->inc(n); return tmp; } friend H operator+(const H& lhs, const H& rhs){ lhs.m_; return H(0); }};class Integer : public Arithmetic< Integer >{public: Integer(T a):m_(a){} Integer(const Integer& t):m_(t.m_){} void inc(int n){ //depended implementation. flexed changed. m_+=n; }private: int m_;};int main(){ Integer a(10); ++a; a++; a+=3; Integer b(10); Integer c = a + b; return 0;}//C++11. friend in template template<class T>class Integer{ friend T; int m_;};class Test{public: void inc( Integer<Test>& t, int n){ t.m_+=n; }};int main(){ Integer<Test> i; Test t; t.inc(i,3);}
0 0
- 学习笔记:几种注入方法
- Spring 几种注入方法
- linux几种关机方法---学习笔记
- 注入DLL的几种方法
- 几种方法绕过防注入
- 绕过防注入的几种方法
- Spring参数注入的几种方法
- Spring IOC的几种注入方法
- 依赖注入的几种配置方法
- Spring学习笔记(10)-----------方法注入
- Spring学习笔记—常用注入方法
- Spring学习笔记二(Bean注入的几种方式)
- spring学习笔记(1)-spring依赖注入的几种方式
- 学习笔记--linq链接数据库的几种方法
- java学习笔记-Java实现几种常见排序方法
- 学习笔记:Android里JSON解析的几种方法
- CSS学习笔记-导入CSS的几种方法(三)
- Hive学习笔记 --- 执行Hive操作的几种方法
- 如何进行Monkey Test
- Linux网络编程(2):UDP客户服务程序设计
- 概率图模型基础
- Mac OS使用技巧之十一:隐藏launchpad中图标的方法
- android sd卡路径正确获取 双sd卡获取
- 学习笔记:几种注入方法
- 淘码手机验证码平台——唯一可以批量接收验证码及批量解封账号的平台
- C++中的头文件和源文件
- Android应用程序的数据存放目录解说
- android 获取当前程序路径
- 编程主要都是基于JavaScript
- 【hdu】Mayor's posters(线段树区间问题)
- 字符串替换
- DOS攻击之SYN攻击原理