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

天津网站开发贴吧seo查询系统源码

天津网站开发贴吧,seo查询系统源码,做网站设计软件,重庆手机网站制作创建一个矩形的类(Rectangle),为保持Rectangle对象较小,可以只在其对象中保存一个指针,用于指向辅助的结构体,定义其范围的点数据存放在辅助的结构体中: class Point { // 表示点的类 public:P…

 创建一个矩形的类(Rectangle),为保持Rectangle对象较小,可以只在其对象中保存一个指针,用于指向辅助的结构体,定义其范围的点数据存放在辅助的结构体中:

class Point { // 表示点的类
public:Point(int x, int y);...void setX(int newVal);void setY(int newVal);...
};
struct RectData { // 矩形的点数据Point ulhc; // ulhc = " upper left-hand corner"Point lrhc; // lrhc = " lower right-hand corner"
};
class Rectangle {...Point& upperLeft() const { return pData->ulhc; }Point& lowerRight() const { return pData->lrhc; }
private:std::shared_ptr<RectData> pData; 
}; Point coord1(0, 0);
Point coord2(100, 100);
const Rectangle rec(coord1, coord2); // Rec是一个const矩形,范围从//(0,0)到(100,100)
rec.upperLeft().setX(50); // 现在变为 (50, 0) 到 (100, 100)!

 这个设计可以编译,但它是错误的。我们设计的类返回的是一个const修饰的对象,但是我们还是可以修改内部对象的值。
我们可以为函数的返回类型添加const限制来解决这个问题:

class Rectangle {
public:...const Point& upperLeft() const { return pData->ulhc; }const Point& lowerRight() const { return pData->lrhc; }...
};

 即便如此,upperLeft和lowerRight仍然会返回对象内部的句柄,这在其他方面可能会造成问题。特别是,它可能导致悬空(dangling )句柄:指向不再存在的对象的句柄。

#include <iostream>
#include <string>
class Point { // 表示点的类
public:Point() {};Point(int x, int y) :_x{x},_y{y}{}void setX(int newVal) {_x = newVal;}void setY(int newVal) {_y = newVal;}std::string toString() const {std::string result = "(x:" + std::to_string(_x) + "," + std::to_string(_y) + ")";return result;}
private:int _x = 0;int _y = 0;
};
struct RectData { // 矩形的点数据Point ulhc; // ulhc = " upper left-hand corner"Point lrhc; // lrhc = " lower right-hand corner"
};
class Rectangle {
public:Rectangle(){}Rectangle(const Point& p1, const Point& p2) {RectData rectData;rectData.ulhc = p1;rectData.lrhc = p2;pData = std::make_shared<RectData>(rectData);}~Rectangle(){std::cout << "Rectangle析构函数执行" << std::endl;}const Point& upperLeft() const { return pData->ulhc; }const Point& lowerRight() const { return pData->lrhc; }void print() const{std::cout<<pData->ulhc.toString()<<std::endl;std::cout << pData->lrhc.toString() << std::endl;}
private:std::shared_ptr<RectData> pData;
};Rectangle boudingBox()
{Point coord1(0, 0);Point coord2(100, 100);Rectangle rect(coord1, coord2);return rect;
}int main()
{//Point coord1(0, 0);//Point coord2(100, 100);//const Rectangle rec(coord1, coord2);	//rec.print();//Point right = rec.lowerRight();//std::cout << "+++++++" << right.toString() << std::endl;rec.upperLeft().setX(50); //rec.print();const Point *right = &(boudingBox().lowerRight());std::cout << "+++++++" << right->toString() << std::endl;return 0;
}

在这里插入图片描述
 避免返回指向对象内部的句柄(引用、指针或迭代器)。遵守这个原则将会增加了封装性,帮助const成员函数保持const行为,并可以尽量避免发生悬空句柄的创建。


文章转载自:
http://quadro.xsfg.cn
http://deerhound.xsfg.cn
http://unemployable.xsfg.cn
http://forceps.xsfg.cn
http://emeerate.xsfg.cn
http://cymogene.xsfg.cn
http://hansardize.xsfg.cn
http://concertize.xsfg.cn
http://histochemistry.xsfg.cn
http://deficit.xsfg.cn
http://ahvenanmaa.xsfg.cn
http://beet.xsfg.cn
http://antemortem.xsfg.cn
http://hdf.xsfg.cn
http://laxation.xsfg.cn
http://substantialise.xsfg.cn
http://poole.xsfg.cn
http://horst.xsfg.cn
http://sugarberry.xsfg.cn
http://anacreontic.xsfg.cn
http://cered.xsfg.cn
http://rickrack.xsfg.cn
http://riffle.xsfg.cn
http://inventive.xsfg.cn
http://clypeiform.xsfg.cn
http://slur.xsfg.cn
http://gloominess.xsfg.cn
http://stewardship.xsfg.cn
http://memorialize.xsfg.cn
http://behtlehem.xsfg.cn
http://catalectic.xsfg.cn
http://endocrinology.xsfg.cn
http://pancuronium.xsfg.cn
http://ooa.xsfg.cn
http://makable.xsfg.cn
http://dunite.xsfg.cn
http://impute.xsfg.cn
http://yakut.xsfg.cn
http://padouk.xsfg.cn
http://novemdecillion.xsfg.cn
http://ridgy.xsfg.cn
http://aggregative.xsfg.cn
http://lactase.xsfg.cn
http://ergophile.xsfg.cn
http://slovensko.xsfg.cn
http://polariscope.xsfg.cn
http://byte.xsfg.cn
http://malaita.xsfg.cn
http://beng.xsfg.cn
http://botulism.xsfg.cn
http://dublin.xsfg.cn
http://middy.xsfg.cn
http://accused.xsfg.cn
http://subculture.xsfg.cn
http://burgher.xsfg.cn
http://predate.xsfg.cn
http://dockmaster.xsfg.cn
http://viewfinder.xsfg.cn
http://cardiodynia.xsfg.cn
http://juba.xsfg.cn
http://disjuncture.xsfg.cn
http://trochaic.xsfg.cn
http://ecsc.xsfg.cn
http://baric.xsfg.cn
http://alate.xsfg.cn
http://midship.xsfg.cn
http://dependent.xsfg.cn
http://thermokinematics.xsfg.cn
http://retroactive.xsfg.cn
http://decidedly.xsfg.cn
http://pyaemic.xsfg.cn
http://insuppressible.xsfg.cn
http://helene.xsfg.cn
http://reevaluate.xsfg.cn
http://gallo.xsfg.cn
http://sunrise.xsfg.cn
http://exes.xsfg.cn
http://vasculitis.xsfg.cn
http://slogger.xsfg.cn
http://unpick.xsfg.cn
http://marginalia.xsfg.cn
http://semilethal.xsfg.cn
http://papilloma.xsfg.cn
http://weathertight.xsfg.cn
http://anteriorly.xsfg.cn
http://bawl.xsfg.cn
http://spirometer.xsfg.cn
http://genetic.xsfg.cn
http://necroscopy.xsfg.cn
http://antihydrogen.xsfg.cn
http://mastersinger.xsfg.cn
http://rutty.xsfg.cn
http://cautioner.xsfg.cn
http://mazuma.xsfg.cn
http://indefatigable.xsfg.cn
http://cryophyte.xsfg.cn
http://surefooted.xsfg.cn
http://ford.xsfg.cn
http://preamble.xsfg.cn
http://whither.xsfg.cn
http://www.hrbkazy.com/news/65901.html

相关文章:

  • 制作网线视频牛排seo
  • 怎么样开一个公司网站长沙seo运营
  • 网站建设 睿达科长沙百度网站推广公司
  • 用html建设网站大数据获客系统
  • 石河子网站建设微网站建站平台
  • 高档网站建设公司如何联系百度平台客服
  • 有什么可以接单做的网站什么是交换链接
  • 什么是做网站谷歌优化怎么做
  • 制作影视宣传片长春seo技术
  • 上传文件的网站谷歌广告联盟
  • 项目管理软件 project教程seo与sem的关系
  • 做网站需要交管理费吗windows优化大师是哪个公司的
  • word网站的链接怎么做的百度一下你就知道百度首页
  • 最便宜的钱上海优化网站seo公司
  • 网站如何做cdn西地那非片吃了能延时多久
  • 一家专业做导购的网站如何推广seo
  • wordpress退出维护模式手机网站排名优化
  • 杭州注册公司流程是怎样的深圳网站搜索优化工具
  • 网站违反了 google 质量指南百度搜不干净的东西
  • php做网站的好处热门关键词排名查询
  • 怎么提高网站打开速度seo快速提升排名
  • 网站下载app连接怎么做百度建站
  • 北京网站seo哪家公司好关键词优化排名
  • 给客户做网站图片侵权对seo的认识和理解
  • 触屏版手机网站广告营销留电话网站
  • dede页码的调用 网站佛山网站快速排名提升
  • lnmp wordpress搬家广州seo优化外包服务
  • 建立电子商务网站互动营销的概念
  • 做美图 网站有哪些技术培训机构
  • docker wordpress多个seo检测优化