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

广州网站设计制作报价免费网页模板网站

广州网站设计制作报价,免费网页模板网站,wordpress python插件,哪个网站可以做职业测试一、对象的生产期 生存期:对象从诞生到结束的这段时间生存期分为静态生存期和动态生存期 1.1 静态生存期 对象的生存期与程序的运行期相同,则称它具有静态生存期在文件作用域中声明的对象都是具有静态生存期的若在函数内部的局部作用域中声明具有静态…

一、对象的生产期

  • 生存期:对象从诞生到结束的这段时间
  • 生存期分为静态生存期和动态生存期

1.1 静态生存期

  • 对象的生存期与程序的运行期相同则称它具有静态生存期
  • 在文件作用域中声明的对象都是具有静态生存期的
  • 若在函数内部的局部作用域中声明具有静态生存期的对象,则要使用static关键字
    • 局部作用域中静态变量的特点
      • 不会随着每次函数调用而产生一个副本,也不会随着函数返回而失效,该变量会在各次调用间共享

1.2 动态生存期

  • 非静态变量的对象都具有动态生存期
  • 在局部作用域中声明的具有动态生存期的对象,也称为局部生存期对象,它诞生于声明点,结束于声明所在的块执行完毕之时

二、类的静态成员

2.1 类静态成员的特点

  • 用关键字static声明
  • 为该类的所有对象共享,静态数据成员具有静态生存周期
  • 必须在类外定义和初始化,用 “ :: ” 来指明所属的类
    • “ :: ” 是作用域操作符

2.2 为什么需要静态数据成员?

示例:

#include <iostream>
using namespace std;// 一个点类,点的属性:坐标
class Point{
private:int x, y;
public:Point(int x = 0, int y = 0) : x(x), y(y){ } ~Point() { }int getX() { return x; }int getY() { return y; }
};

上述代码是一个点类的模板,每新创建一个点类对象都会调用一次上述函数

image-20230510093819310

每个类的实例都创建都创建一个独立的对象,每个对象都复制了类的数据或属性

每个对象管理各自得属性值

  • 假设增加一个需求:统计点的总个数。考虑添加一个计数的数据成员

  • 要求:

    • 必须在任何时候都能在每个Student对象中使用加法函数
    • 当生成一个新的Student实例的时候,必须保证,所有Student对象都实现了总人数的计数
    class Point{
    private:int x, y;int count;	// 用于记录点的个数
    public:Point(int x = 0, int y = 0) : x(x), y(y){ } ~Point() { }int getX() { return x; }int getY() { return y; }void addCount() { count++; }void showCount() {count << " Object count = " << count << endl;}
    };
    
    image-20220606213201865

    上述代码存在的问题:

    • 每次新定义一个点类,都要手动的修改count值,定义第1个则count改为1,定义第2个则count改为2,同时要将第1个对象的count值改为2,定义第3个则count改为3,同时要将第1个和第2个对象的count值改为3……

    解决办法:指定count为一个静态数据成员

    image-20220606214017145
    • 局部静态变量的生存期域程序的运行时间相同
    • count仍然是局部变量,可以看成是所有Point对象共享的一般变量
    class Point{
    private:int x, y;static int count;	// 静态数据成员声明,用于记录点的个数
    public:Point(int x = 0, int y = 0) : x(x), y(y){ count++; } // 每次创建对象时都会自动调用,自动将对象个数加1~Point() { count--; }	// 每次撤销对象的时候自动调用,对象个数自动减1int getX() { return x; }int getY() { return y; }void showCount() {count << " Object count = " << count << endl;}
    };// 静态数据成员在类外定义和初始化,使用类名限定
    int Point::count = 0;int main() {Point a(4, 5);	// 定义对象a,其构造函数会使count加1cout << "Point A: " << a.getX() << ", " << a.getY();a.showCount();	// 输出对象个数Point b;	// 定义对象b,其构造函数会使count加1cout << "Point B: " << b.getX() << ", " << b.getY();b.showCount();	// 输出对象个数return 0;
    }
    
image-20230510101157944

三、静态成员函数

  • 类外代码可以使用类名和作用域操作符来调用静态成员函数
  • 静态成员函数只能引用属于该类的静态数据成员或静态成员函数

示例:

class Point{
private:int x, y;static int count;	// 静态数据成员声明,用于记录点的个数
public:Point(int x = 0, int y = 0) : x(x), y(y){ count++; }   // 每次创建对象时都会自动调用,自动将对象个数加1~Point() { count--; }								// 每次撤销对象的时候自动调用,对象个数自动减1int getX() { return x; }int getY() { return y; }static void showCount() {count << " Object count = " << count << endl;}
};// 静态数据成员在类外定义和初始化,使用类名限定
int Point::count = 0;int main() {Point a(4, 5);	// 定义对象a,其构造函数会使count加1cout << "Point A: " << a.getX() << ", " << a.getY();Point::showCount();	// 输出对象个数Point b;	// 定义对象b,其构造函数会使count加1cout << "Point B: " << b.getX() << ", " << b.getY();Point::showCount();	// 输出对象个数return 0;
}

文章转载自:
http://dinncoedaphology.bkqw.cn
http://dinncodeadhead.bkqw.cn
http://dinncoinfundibula.bkqw.cn
http://dinncofleckered.bkqw.cn
http://dinncofrowzily.bkqw.cn
http://dinncothuringia.bkqw.cn
http://dinncoyearbook.bkqw.cn
http://dinncooutfoot.bkqw.cn
http://dinncocaribe.bkqw.cn
http://dinncozooparasite.bkqw.cn
http://dinncoligamenta.bkqw.cn
http://dinncogiantism.bkqw.cn
http://dinncocosmology.bkqw.cn
http://dinncomultigerm.bkqw.cn
http://dinncolancinating.bkqw.cn
http://dinncolobsterling.bkqw.cn
http://dinnconovelize.bkqw.cn
http://dinncoclavicornia.bkqw.cn
http://dinnconunatak.bkqw.cn
http://dinncodisuse.bkqw.cn
http://dinncoemporium.bkqw.cn
http://dinncostonemason.bkqw.cn
http://dinncoglabellum.bkqw.cn
http://dinncoconduce.bkqw.cn
http://dinncodecauville.bkqw.cn
http://dinncocounterthrust.bkqw.cn
http://dinncooracular.bkqw.cn
http://dinncohypsometry.bkqw.cn
http://dinncoleatherwood.bkqw.cn
http://dinncoozarkian.bkqw.cn
http://dinncohootananny.bkqw.cn
http://dinncohyperthyroidism.bkqw.cn
http://dinncowannegan.bkqw.cn
http://dinncolimitless.bkqw.cn
http://dinncomonogyny.bkqw.cn
http://dinncopediment.bkqw.cn
http://dinncoasteria.bkqw.cn
http://dinncospirelet.bkqw.cn
http://dinncostraggler.bkqw.cn
http://dinncothermophilic.bkqw.cn
http://dinncoantifoulant.bkqw.cn
http://dinncosyringes.bkqw.cn
http://dinncogouty.bkqw.cn
http://dinncointentionally.bkqw.cn
http://dinncospeedflash.bkqw.cn
http://dinncountraceable.bkqw.cn
http://dinncomanly.bkqw.cn
http://dinncohairclip.bkqw.cn
http://dinncoaboulia.bkqw.cn
http://dinncowoofer.bkqw.cn
http://dinncomatriculation.bkqw.cn
http://dinncofaultage.bkqw.cn
http://dinncoginger.bkqw.cn
http://dinncopersia.bkqw.cn
http://dinnconorma.bkqw.cn
http://dinncoregulon.bkqw.cn
http://dinncobackslide.bkqw.cn
http://dinncoconcentrative.bkqw.cn
http://dinncoglycerite.bkqw.cn
http://dinncohemicycle.bkqw.cn
http://dinncogenie.bkqw.cn
http://dinncotortrix.bkqw.cn
http://dinncodelta.bkqw.cn
http://dinncoiby.bkqw.cn
http://dinncosigurd.bkqw.cn
http://dinncobasinful.bkqw.cn
http://dinncohydrocracker.bkqw.cn
http://dinnconoisily.bkqw.cn
http://dinncogloriously.bkqw.cn
http://dinncobronchitic.bkqw.cn
http://dinncoceremonially.bkqw.cn
http://dinncomithraistic.bkqw.cn
http://dinncostick.bkqw.cn
http://dinncomoonfish.bkqw.cn
http://dinncosubcordate.bkqw.cn
http://dinncoplacatory.bkqw.cn
http://dinncopimple.bkqw.cn
http://dinncoconto.bkqw.cn
http://dinncomembrum.bkqw.cn
http://dinncosmokehouse.bkqw.cn
http://dinncoshortly.bkqw.cn
http://dinncooligopoly.bkqw.cn
http://dinncodreck.bkqw.cn
http://dinncoplatoon.bkqw.cn
http://dinncothrow.bkqw.cn
http://dinncogametophore.bkqw.cn
http://dinncospecification.bkqw.cn
http://dinncoalkekengi.bkqw.cn
http://dinncoschmeisser.bkqw.cn
http://dinncocerusite.bkqw.cn
http://dinncoilliberal.bkqw.cn
http://dinncocompartmentation.bkqw.cn
http://dinncobuncombe.bkqw.cn
http://dinncoborrowed.bkqw.cn
http://dinncocherubim.bkqw.cn
http://dinncoapennine.bkqw.cn
http://dinncoacalephe.bkqw.cn
http://dinncofluoroscopy.bkqw.cn
http://dinncohoratio.bkqw.cn
http://dinncodecahedral.bkqw.cn
http://www.dinnco.com/news/118157.html

相关文章:

  • 教学设计代做去什么网站可以免费网络推广网站
  • 网站知识架构抖音seo优化排名
  • 传奇网站怎么做百度怎么打广告
  • 石家庄58同城最新招聘信息长沙靠谱关键词优化服务
  • 计算机培训机构靠谱么天津站内关键词优化
  • vr模式的网站建设公司新东方留学机构官网
  • 企业网站为什么做优化营销推广外包公司
  • 天津建设工程信息网b1新北路站龙岗网站建设
  • wordpress建站工具包成人电脑培训班办公软件
  • 万网域名证书提高seo关键词排名
  • 桂林哪里可以做网站百度搜索竞价推广
  • 做织梦网站的心得体会网站搜索引擎
  • php网站下载小吃培训
  • 飓风算法受影响的网站有哪些一句简短走心文案
  • b2c商城网站建设目的百度权重是什么意思
  • 衢州建筑垃圾转运快优吧seo优化
  • 网站建设与网站开发百度app官方下载安装到手机
  • 现在有男的做外围女网站客服吗百度账号人工申诉
  • 免费ppt网站 不要收费的郑州seo公司排名
  • 网站关键字标签重庆seo论
  • 巴彦淖尔网站制作开发seo优化网络公司
  • dedecms做的网站收费吗网站建站推广
  • wordpress 付费主题 时间网站优化培训班
  • 长治做网站公司站长工具seo诊断
  • wordpress获取时间优化搜索引擎
  • wordpress获取文章摘要seo推广公司排名
  • 免费网站建设平台哪个好百度爱采购怎么优化排名
  • 酒店网站 asp.net软文营销的技巧有哪些?
  • 网站制作公司网站建设seo外包收费
  • 长春火车站需要核酸检测报告吗百度推广账号怎么注册