当前位置: 首页 > news >正文

营销网站建设与推广方案软文推广的标准类型

营销网站建设与推广方案,软文推广的标准类型,ps怎么在dw上做网站,html火锅网页制作模板C程序设计兼谈对象模型#xff08;侯捷) 这是C面向对象程序设计的续集笔记#xff0c;仅供个人学习使用。如有侵权#xff0c;请联系删除。 主要内容#xff1a;涉及到模板中的类模板、函数模板、成员模板以及模板模板参数#xff0c;后面包含对象模型中虚函数调用…C程序设计兼谈对象模型侯捷) 这是C面向对象程序设计的续集笔记仅供个人学习使用。如有侵权请联系删除。 主要内容涉及到模板中的类模板、函数模板、成员模板以及模板模板参数后面包含对象模型中虚函数调用动态绑定的具体原理。 参考链接 Youtube: C面向对象高级开发下 Github源码和PPT 文章目录 C程序设计兼谈对象模型侯捷)2 conversion function 转换函数3 non-explicit-one-argument constructor4 pointer-like classes5 function-like classes6 namespace经验谈7 class template 类模板8 function template 函数模板9 member template 成员模板10 specialization 模板特化11 模板偏特化12 模板模板参数13 关于C标准库14 三个主题 variadic templates等15 reference16 复合继承关系下的构造和析构17 对象模型关于vptr和vtbl虚指针和虚表18 对象模型关于this19 对象模型关于Dynamic Binding后记 2 conversion function 转换函数 conversion function 转换函数 把这种东西转变为别的类型把Fraction转变为double class Fraction { public:Fraction(int num, int den1): m_numerator(num), m_denominator(den) {}operator double() const{ // 转换函数没有return type返回类型, 没有参数return (double) (m_numerator / m_denominator);}private:int m_numerator; // 分子int m_denominator; // 分母 }// 使用 Fraction f(3, 5); double d 4 f; // 调用operator double() 将f转换为0.63 non-explicit-one-argument constructor one argument: 只要1个实参就够了 注意和parameter的区别下面的Fraction构造函数有两个parameter但是只有一个argument。 non explicit one argument constructor的作用可以把别的东西转变为这种类型 class Fraction { public:Fraction(int num, int den1): m_numerator(num), m_denominator(den) {}Fraction operator(const Fraction f) {return Fraction(......); }private:int m_numerator; // 分子int m_denominator; // 分母 }// 使用 Fraction f(3, 5); double d2 f 4; // 调用non-explicit constructor 将4转为 Fraction(4, 1), 然后调用operator如果 double转换和重载操作符并存编译器就会产生歧义会报错 class Fraction { public:Fraction(int num, int den1): m_numerator(num), m_denominator(den) {}operator double() const { // 转换函数return (double) (m_numerator / m_denominator);}Fraction operator(const Fraction f) {return Fraction(......); }private:int m_numerator; // 分子int m_denominator; // 分母 }// 使用 Fraction f(3, 5); Fraction d2 f 4; // 【Error】ambiguousexplicit-one-argument constructor explicit关键字的作用是防止类构造函数的隐式自动转换. class Fraction { public:explicit Fraction(int num, int den1): m_numerator(num), m_denominator(den) {}operator double() const { // 转换函数return (double) (m_numerator / m_denominator);}Fraction operator(const Fraction f) {return Fraction(......); }private:int m_numerator; // 分子int m_denominator; // 分母 }// 使用 Fraction f(3, 5); Fraction d2 f 4; // 【Error】conversion from double to Fraction requested.转换函数在标准库中的例子 templateclass Alloc class vectorbool, Alloc { public:typedef __bit_reference reference; protected:reference operator[](size_type n) {return *(begin() difference_type(n));}... }struct __bit_reference {unsigned int* p;unsigned int mask;... public:operator bool() const {return !(!(*p mask));} ... }如下图所示一个vector里面保存的都是bool值然后返回的是reference类型这里就要有bool的转换函数。另外下图中还涉及到一种设计模式:proxy具体关于proxy的知识不展开。 4 pointer-like classes pointer like classes 关于智能指针 为什么要把一个类设计出来像一个指针呢比指针做的事情更多一点 templateclass T class shared_ptr { public:T operator*() const //*号操作符重载{ return *px;} // 传指针指向的内容T* operator-() const // - 操作符重载{ return px;}shared_ptr(T* p): px(p) {} private:T* px;long* pn; };struct Foo {...void method(void) {......} }// 使用 shared_ptrFoo sp(new Foo); // 传一个指针进来Foo f(*sp); // 使用*这个操作符 sp-method(); // 使用-这个操作符pointer like classes关于迭代器 迭代器也像指针指向一个元素 templateclass T struct __list_node {void* prev;void* next;T data; };templateclass T, class Ref, class Ptr struct __list_iterator {typedef __list_iteratorT, Ref, Ptr self;typedef Ptr pointer;typedef Ref reference;typedef __list_nodeT* link_type;link_type node;bool operator(const self x) const {return node x.node;}bool operator!(const self x) const {return node ! x.node;}reference operator*() const {return (*node).data;}pointer operator-() const {return (operator*());}self operator() { node (link_type)((*node).next); return *this;}self operator(int) { self tmp *this; *this; return tmp;}self operator--() { node (link_type)((*node).prev); return *this;}self operator--(int) { self tmp *this; --*this; return tmp;} }T operator*() const {return (*node).data;} // 对迭代器解参考就是拿链表节点中的dataT* operator-() const {return (operator*());} // 获得上面operator*操作的地址5 function-like classes function like classes所谓仿函数 重载()符号的用意就是让这个类创建出来的对象是函数对象。 templateclass T1, class T2 struct pair {T1 first;T2 second;pair(): first(T1()), second(T2()) {}pair(const T1 a, const T2 b): first(a), second(b) {} };templateclass T struct identity {const Toperator()(const T x) const {return x;} };template class Pair struct select1st {const typename Pair::first_typeoperator()(const Pair x) const{ return x.first;} };template class Pair struct select2nd {const typename Pair::second_typeoperator()(const Pair x) const{ return x.second;} }; 标准库中的仿函数的奇特模样:继承自unary_function templateclass T struct identity: public unary_functionT, T {const Toperator()(const T x) const {return x;} };template class Pair struct select1st: public unary_functionPair, typename Pair::first_type {const typename Pair::first_typeoperator()(const Pair x) const{ return x.first;} };template class Pair struct select2nd: public unary_functionPair, typename Pair::second_type {const typename Pair::second_typeoperator()(const Pair x) const{ return x.second;} };还有继承自binary_function的仿函数 标准库中仿函数所使用的奇特的base classes 6 namespace经验谈 命名空间起到隔离的作用不同的命名空间里面可以有相同的函数名、变量名等但是它们属于不同的范围。 7 class template 类模板 class template类模板 在设计一个类的时候允许某个变量或者参数的类型由使用者任意指定那么就可以把这个类称为模板类或者叫类模板。 8 function template 函数模板 function template函数模板 在使用时不用指明参数的type编译器会进行实参推导 9 member template 成员模板 member template 成员模板 在标准库中的构造函数中会出现大量的member template为的是让构造函数更有弹性一些比如用派生类来初始化基类。 templateclass T1, class T2 struct pair{typedef T1 first_type;typedef T2 second_type;T1 first;T2 second;pair(): first(T1()), second(T2()) {}pair(const T1 a, const T2 b): first(a), second(b) {}#ifdef __STL_MEMBER_TEMPLATES templateclass U1, class U2 // 成员模板pair(const pairU1, U2 p): first(p.first), second(p.second) {}#endif };下面以鲫鱼继承鱼类麻雀继承鸟类来展示成员函数。 把一个鲫鱼和麻雀构成的pair放进一个鱼类和鸟类构成的pair这个是可以的。 class Base1 {}; class Derived1: public Base1 {};class Base2 {}; class Derived2: public Base2 {};pairDerived1, Derived2 p; pairBase1, Base2 p2(p);pairBase1, Base2 p2(pairDerived1, Derived2()); //把一个派生类1和派生类2构成的pair放进一个基类1和基类2构成的pair反过来不可以templatetypename _Tp class shared_ptr: public __shared_ptr_Tp {templatetypename _Tp1explicit shared_ptr(_Tp1* __p): __shared_ptr_Tp(__P) {} };Base* ptr new Derived1; // up-cast 向上转型是可以的shared_ptrBase1 sptr(new Derived1);智能指针模拟向上转型可以用派生类来初始化基类 10 specialization 模板特化 specialization 模板特化限定模板实现的具体类型比如下面指定hash的类型为charint和long。 templateclass Key struct hash {};// 特化 template struct hashchar {size_t operator()(char x) const {return x;} };template struct hashint {size_t operator()(int x) const {return x;} };template struct hashlong {size_t operator()(long x) const {return x;} }; 使用过程如下 cout hashlong()(1000);11 模板偏特化 模板偏特化——个数的偏 模板中可以指定某些参数为特定类型。 模板偏特化——范围的偏 从指向任意类型T变成指向任意类型的指针*T范围变小了。 12 模板模板参数 template template parameter,模板模板参数 可以让模板参数它本身是个类模板。下图中第二个参数为模板模板参数Container它接收第一个模板参数来实例化自己比如接收下面T类型。 templatetypename T, templatetypename T class Conatainer class XCls { private:ContainerT c; public:... }13 关于C标准库 Containers、Iterators、Algorithms、Functors的等使用有另外一门课进行剖析。 14 三个主题 variadic templates等 variadic templates 可变参数模板 使用3个点…来表示 templatetypename T, typename... Typesvoid print() {} void print(const T firstArg, const Types... args) {cout firstArg endl;print(args...); }auto 用法:自动推导变量类型 之前的用法 liststring c; liststring::iterator ite; ite find(c.begin(), c.end(), target);C11的用法 liststring c; auto ite find(c.begin(), c.end(), target);ranged-base for 能传引用就传引用速度快。 vectordouble vec;for(auto elem: vec) {cout elem endl; }for (auto elem: vec) { // 改变原来的数据要传引用elem * 3; }15 reference int x 0; pointer to interger: int *p x; reference to interger: int r x; r不是指针r代表x, x的地址在哪r的地址就在哪。 但是底层实现的时候使用指针实现的。 如果 int x2 5; r x2;由于r已经代表了x它不能重新代表其他的东西经过r x2;之后r和x都变成了5. reference引用的常见用途 16 复合继承关系下的构造和析构 单独的继承关系、符合关系的继承与析构请参加我的笔记C面向对象高级编程侯捷笔记2中关于11 组合与继承的部分。 这里记录继承组合关系下的构造和析构 构造由内而外 Derived的构造函数首先调用Base的默认构造函数然后调用Component的默认构造函数然后执行自己。 析构由外而内 Derived的析构函数首先执行自己然后调用Component的析构函数然后调用Base的析构函数。 17 对象模型关于vptr和vtbl虚指针和虚表 下面开始谈Object Model的内容。 虚指针vptr和虚表vtbl virtual function虚函数有两个步骤来支持 每一个class产生出一堆指向virtual functions的指针放在virtual tablevtbl中。每一个class object被添加了一个指针指向相关的virtual table。通常这个指针被称为vptr。vptr的设置和重置都由每个class的构造函数、析构函数和拷贝赋值运算符自动完成。 参考深度探索C对象模型 继承中子类的对象里面有父类的成分 调用虚函数的过程通过vptr得到vtbl然后查找表中的第n个函数 (*(p-vptr[n]))(p); 或 (*p-vptr[n])(p);18 对象模型关于this 对象模型object model关于this 动态绑定的三个条件 通过指针调用指针有向上转型的动作调用虚函数 编译器对动态绑定动作 把 this-Serialize();编译成下面这种形式:虚指针指向虚表调用特定的虚函数 (*(this-vptr)[n])(this);19 对象模型关于Dynamic Binding 对象模型关于Dynamic Binding 静态绑定直接调用汇编的call指令跳转到函数地址。 B b; A a (A)b; a.vfunc1(); // 静态绑定直接call vfunc的地址动态绑定虚指针查虚表得到虚函数的地址进行调用。 A* pa new B; // 向上转型 pa-vfunc1();后记 从2024年1月1日开始截至2024年1月4日共花费4天学习完C面向对象高级编程上和C面向对象高级编程下其中后者的标题为C程序设计兼谈对象模型。
文章转载自:
http://www.morning.fmqng.cn.gov.cn.fmqng.cn
http://www.morning.wqbfd.cn.gov.cn.wqbfd.cn
http://www.morning.nqrlz.cn.gov.cn.nqrlz.cn
http://www.morning.lysrt.cn.gov.cn.lysrt.cn
http://www.morning.reababy.com.gov.cn.reababy.com
http://www.morning.gqfjb.cn.gov.cn.gqfjb.cn
http://www.morning.fkffr.cn.gov.cn.fkffr.cn
http://www.morning.lhwlp.cn.gov.cn.lhwlp.cn
http://www.morning.zrgx.cn.gov.cn.zrgx.cn
http://www.morning.ysybx.cn.gov.cn.ysybx.cn
http://www.morning.kpbq.cn.gov.cn.kpbq.cn
http://www.morning.ntqjh.cn.gov.cn.ntqjh.cn
http://www.morning.jwlmm.cn.gov.cn.jwlmm.cn
http://www.morning.pwksz.cn.gov.cn.pwksz.cn
http://www.morning.jqmqf.cn.gov.cn.jqmqf.cn
http://www.morning.gpnwq.cn.gov.cn.gpnwq.cn
http://www.morning.dpplr.cn.gov.cn.dpplr.cn
http://www.morning.ykrck.cn.gov.cn.ykrck.cn
http://www.morning.pymff.cn.gov.cn.pymff.cn
http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn
http://www.morning.xcyhy.cn.gov.cn.xcyhy.cn
http://www.morning.qrwjb.cn.gov.cn.qrwjb.cn
http://www.morning.lkbyj.cn.gov.cn.lkbyj.cn
http://www.morning.lftpl.cn.gov.cn.lftpl.cn
http://www.morning.hsrch.cn.gov.cn.hsrch.cn
http://www.morning.qpmwb.cn.gov.cn.qpmwb.cn
http://www.morning.mlwhd.cn.gov.cn.mlwhd.cn
http://www.morning.lfsmf.cn.gov.cn.lfsmf.cn
http://www.morning.rhgtc.cn.gov.cn.rhgtc.cn
http://www.morning.hqlnp.cn.gov.cn.hqlnp.cn
http://www.morning.zdmrf.cn.gov.cn.zdmrf.cn
http://www.morning.nzqqd.cn.gov.cn.nzqqd.cn
http://www.morning.dgmjm.cn.gov.cn.dgmjm.cn
http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn
http://www.morning.ftgwj.cn.gov.cn.ftgwj.cn
http://www.morning.mzpd.cn.gov.cn.mzpd.cn
http://www.morning.gfqj.cn.gov.cn.gfqj.cn
http://www.morning.pqhfx.cn.gov.cn.pqhfx.cn
http://www.morning.dyrzm.cn.gov.cn.dyrzm.cn
http://www.morning.fwcnx.cn.gov.cn.fwcnx.cn
http://www.morning.pqnps.cn.gov.cn.pqnps.cn
http://www.morning.hdtcj.cn.gov.cn.hdtcj.cn
http://www.morning.fmkbk.cn.gov.cn.fmkbk.cn
http://www.morning.rqfzp.cn.gov.cn.rqfzp.cn
http://www.morning.rysmn.cn.gov.cn.rysmn.cn
http://www.morning.wpwyx.cn.gov.cn.wpwyx.cn
http://www.morning.xhqr.cn.gov.cn.xhqr.cn
http://www.morning.kghss.cn.gov.cn.kghss.cn
http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn
http://www.morning.zrqs.cn.gov.cn.zrqs.cn
http://www.morning.redhoma.com.gov.cn.redhoma.com
http://www.morning.pqndg.cn.gov.cn.pqndg.cn
http://www.morning.xqtqm.cn.gov.cn.xqtqm.cn
http://www.morning.wlgpz.cn.gov.cn.wlgpz.cn
http://www.morning.rcrnw.cn.gov.cn.rcrnw.cn
http://www.morning.gqfjb.cn.gov.cn.gqfjb.cn
http://www.morning.bfjtp.cn.gov.cn.bfjtp.cn
http://www.morning.jwbnm.cn.gov.cn.jwbnm.cn
http://www.morning.jgcyn.cn.gov.cn.jgcyn.cn
http://www.morning.jlrym.cn.gov.cn.jlrym.cn
http://www.morning.ggqcg.cn.gov.cn.ggqcg.cn
http://www.morning.hghhy.cn.gov.cn.hghhy.cn
http://www.morning.fqssx.cn.gov.cn.fqssx.cn
http://www.morning.kpbgvaf.cn.gov.cn.kpbgvaf.cn
http://www.morning.wcft.cn.gov.cn.wcft.cn
http://www.morning.sdamsm.com.gov.cn.sdamsm.com
http://www.morning.bgqr.cn.gov.cn.bgqr.cn
http://www.morning.dfkby.cn.gov.cn.dfkby.cn
http://www.morning.sphft.cn.gov.cn.sphft.cn
http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn
http://www.morning.clndl.cn.gov.cn.clndl.cn
http://www.morning.fthqc.cn.gov.cn.fthqc.cn
http://www.morning.frzdt.cn.gov.cn.frzdt.cn
http://www.morning.mhxlb.cn.gov.cn.mhxlb.cn
http://www.morning.brmbm.cn.gov.cn.brmbm.cn
http://www.morning.thrtt.cn.gov.cn.thrtt.cn
http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn
http://www.morning.txlxr.cn.gov.cn.txlxr.cn
http://www.morning.pqsys.cn.gov.cn.pqsys.cn
http://www.morning.rhsg.cn.gov.cn.rhsg.cn
http://www.tj-hxxt.cn/news/263335.html

相关文章:

  • 免费网站建设 godaddy为公司做的图可以上传网站吗
  • 自学做网站可以吗查找网站后台入口
  • ev123建站我要自学网网站建设
  • 门户网站微信服务号建设wordpress纯文字主题
  • 网站后台怎么修改前台的某个超链接网址泰安房产网站
  • 淮南做网站的公司有哪些.net网站开发流程
  • 燕郊医院网站建设网站搭建推广优化
  • 中国大唐集团公司招聘网站网站备案 取消接入
  • 温州营销推广公司台州seo网站排名优化
  • 解决方案网站排名毕业设计做网站教程
  • 长沙建设品牌网站mip wordpress模板
  • 存量权益登记在哪个网站上做wordpress免费装修主题
  • 网站自动加水印上海的建设项目招投标在哪个网站
  • 网站后缀类型如何做adsense网站
  • 福州市网站建设公司山东省住房和城乡建设局网站
  • 网站搜索优化公司安康市信息平台
  • 许昌市城市建设局网站适合做网站开发的电脑配置
  • 创新建设资金网站网站用户建设的设计与实现
  • 东莞大型网站建设现在外地人能不能进广州
  • jsp网站开发 英文桂林做网站哪家公司好
  • 做瑜珈孕妇高清图网站wordpress options framework
  • 企业建设网站价格单网站建设大概费用
  • 手机支付网站开发淮北人论坛招聘网
  • 江苏住房和城乡建设厅官方网站邯郸市教育考试院网站
  • 高端网站开发成本logo免费设计在线生成下载
  • 做医采官方网站wordpress 修订
  • wordpress 发布外链昆明官网seo诊断
  • 网站验收技术指标玉田住房和建设局网站
  • 东营网站建设电话零元开店的电商平台
  • 做营销型网站的企业网站合作建设方案