电影采集网站怎么做seoWordpress慢加内存还是带宽
电影采集网站怎么做seo,Wordpress慢加内存还是带宽,松江新城投资建设集团发展有限公司网站,目字形布局结构的网站1.前言
假设我们需要编写一个程序#xff0c;它能够传送信息到若干不同的公司去。信息要不编译称密码#xff0c;要不就是未加工的文字。如果编译器间我们有足够的信息来决定哪一个信息传至哪一家公司#xff0c;就可以采用基于template的解法#xff1a;
class Company{…1.前言
假设我们需要编写一个程序它能够传送信息到若干不同的公司去。信息要不编译称密码要不就是未加工的文字。如果编译器间我们有足够的信息来决定哪一个信息传至哪一家公司就可以采用基于template的解法
class Company{public:...void sendClearText(const std::string msg);void sendEncrypted(const std::string msg);...};
class CompanyB{public:...void sendCleartext(const std::string msg);void sendEncrypted(const std::string msg);...
};
...//针对其它公司设计的classes
class MsgInfo{....//这个class用来保存信息以备将来产生信息
};templatetypename Company
class MsdSender{class MsgSender{public:...void sendClear(const MsgInfo info){std::string msg;Company c; c.sendCleartext(msg);}void sendSecret(const MsgInfo info)//类似sendClear{....}}
};
2.实例分析
这个做法能够完成任务但假设我们有时候想要在每次送出信息时log某些信息。derived class可轻易加上这样的功能
templatetypename Company
class LoggingMsgSender:public MsgSenderCompany
{public:...//相关构造函数析构函数等void sendClearMsg(const MsgInfo info){将“传送前”的信息写至logsendClear(info);//调写base class函数这段代码无法通过编译将“传送后”的信息写至log }...
};
注意这里derived class的信息传送函数有一个不同的名称sendClearMsg,与其base class内的名称sendClear不同。能避免遮掩“继承而得”的名称也避免重新定义一个继承而得得non-virtual函数。然而不幸得时上述代码无法通过编译。编译器会抱怨sendClear不存在。我们能看到sendClear()确实在base class内编译器却检测不到它们为什么
问题在于当编译器遇到class template LoggingMsgSender定义式时并不知道它要继承什么样的class。当然它继承的是MsgSenderCompany,但其中的Company是个template参数不到loggingMsgSender被具现化无法知道它是什么。而如果不知道Company是什么就无法知道class MsgSenderCompany看起来是什么-更明确地说是没办法知道它是否有个sendClear函数。
为了让问题更具体化假设我们有个class CompanyZ坚持使用加密通讯
class CompanyZ{public:...void sendEncrypted(const std::string msg);...
};
一般性的MsgSender template对CompanyZ并不合适因为那个template提供了一个sendClear函数其中针对其类型参数Company调用了sendCleartext函数而这对CompanyZ对象并不合理要矫正这个问题我们可以针对CompanyZ产生一个MsgSender特化版
template
class MsgSenderCompany//一个全特化的MsghSender,//它和一般template相同差别在于它删除了sendClear
{public:...void sendSecret(const MsgInfo info){...}};
注意class定义式最前头的“template”语法象征这即不是template,也不是标准的class而是个特化版的MsgSender template,在template实参是CompanyZ时被使用。而这个所谓的模板全特化total template specialization:template MsgSender针对类型CompanyZ特化了而且其特性也是全面性的也就是说一旦类型参数被定义为CompanyZ再没有其它template参数可供变化。
现在MsgSender针对CompanyZ进行了全特化让我们再次考虑derived class 中的LoggingMsgSender:
templateMsgSender:
templatetypename Company
class LoggingMsgSender:public MsgSenderCompany
{public:...void sendClearMsg(const MsgInfo info){//将“传送前”的信号写至log;sendClear(info);//如果·CompanyCompanyZ,这个函数将不存在//将“传送后”的信息写到log}....
};
正如注释所言当base class被指定为MsgSenderCompany时这段代码不合法因为class并未提供sendClear函数那就是为什么C拒绝调用的原因它知道base class template有可能被特化而那个版本可能不提供和一般性template相同的接口。因此它会拒绝在template base classes(模板化基类本例的MsgSenderCompany)内寻找继承而来的名称本例的SendClear。
为了重头来过我们必须有某种办法令C“不进入templatized base classes观察“的行为失效。有三个办法
第一是在base class函数调用动作之前加上”-this“:
templatetypename Company
class LoggingMsgSender:public MsgSenderCompany
{public:...void sendClearMsg(const MsgInfo info){//将”传送前“的休息写至Log;this-sendClear(info);//成立假设sendClear被继承//将传递后的信息写至log}
};
第二是使用using声明式。条款33描述了using 声明式如何将”被掩盖的base class名称带入一个derived class作用域内“我们可以写下sendClearMsg:
templatetypename Company
class LoggingMsgSender:public MsgSenderCompany
{public:using MsgSenderCompany::sendClear;//告诉编译器请他假设sendClear位于base class内...void sendClearMsg(const MsgInfo info){...sendClear(info);//ok,假设sendClear将被继承...}
};
虽然using声明式在这里或在条款33都可有效运作但两处解决问题的本质其实不相同。这里的情况并不是base class名称被derived class名称遮掩而是编译器不进入base class作用域查找于是我们通过Using告诉它。
第三个方法是指出被调用的函数位于base class内
templatetypename Company
class LoggingMsgSender:public MsgSenderCompany
{public:...void sendClearMsg(const MsgInfo info){...MsgSenderCompany::sendClear(info);//ok,假设sendClear将被继承}....};
但这不是一种很满意的方法因为如果被调用的是virtual函数上述的明确资格修斯explicit qualification会关闭”virtual绑定行为“。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/88577.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!