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

手机端移动网站建设宁波网站关键词优化公司

手机端移动网站建设,宁波网站关键词优化公司,注册博客域名做视频网站会怎么样,上海网站设计哪家好对象模型: 成员变量和成员函数分开存储 在C中,类内的成员变量和成员函数分开存储 只有非静态成员变量才属于类的对象上 空对象占用空间: 1字节 C编译器会给每个空对象也分配一个字节空间,是为了区分空对象占内存的位置 每个…

对象模型:

成员变量和成员函数分开存储
在C++中,类内的成员变量和成员函数分开存储
只有非静态成员变量才属于类的对象上

空对象占用空间:   1字节

C++编译器会给每个空对象也分配一个字节空间,是为了区分空对象占内存的位置

每个空对象也应该有一个独一无二的内存地址 

class Person {
public:};void test01()
{Person p;//空对象占用内存空间为:cout << sizeof(p) << endl;
}int main()
{test01();system("pause");return 0;
}

 非静态成员变量占对象空间  属于类的对象上 

class Person {
public://非静态成员变量占对象空间  属于类的对象上          4int m_A;//静态成员变量不占对象空间  不属于类的对象上       4static int m_B;             //类内声明void func()    //非静态成员函数  不属于类的对象上      4{  cout << "m_A:" << this->m_A << endl;}//静态成员函数也不占对象空间    不属于类的对象上     4static void sfunc() {}};
int Person::m_B = 0;       //类外初始化//空对象占多数空间
void test01()
{Person p;//空对象占用内存空间为: 1//C++编译器会给每个空对象也分配一个字节空间,是为了区分空对象占内存的位置//每个空对象也应该有一个独一无二的内存地址cout << sizeof(p) << endl;
}void test02()
{Person p;cout << sizeof(p) << endl;
}int main()
{//test01();test02();system("pause");return 0;
}

this指针:

每一个非静态成员函数只会诞生一份函数实例,也就是说多个同类型的对象会共用一块代码
那么问题是:这一块代码是如何区分那个对象调用自己的呢?

        c++通过提供特殊的对象指针,this指针,解决上述问题。this指针指向被调用的成员函数所属的对象:

1.解决名称冲突;

示例:

class Person
{
public:Person(int age){//this指针指向 被调用的成员函数 所属的对象this->age = age;}int age;
};//解决名称冲突
void test01()
{Person p1(18);cout << "p1.age = " << p1.age << endl;
}int main()
{test01();system("pause");return 0;
}

 

2.在类的非静态成员函数中返回对象本身,可使用return * this 

class Person
{
public:Person(int age){//this指针指向 被调用的成员函数 所属的对象this->age = age;}//值返回    返回一个新的对象//引用得方式返回  不会创建对象 一直返回p2Person& PersonAddAge(Person& p){this->age += p.age;//this指向p2的指针,而*this指向的就是p2这个对象本体return *this;}int age;
};//1 解决名称冲突
void test01()
{Person p1(18);cout << "p1.age = " << p1.age << endl;
}//2 返回对象本身,可使用return * this
void test02()
{Person p1(10);Person p2(10);//链式编程思想p2.PersonAddAge(p1).PersonAddAge(p1).PersonAddAge(p1);cout << "p2.age = " << p2.age << endl;
}int main()
{test01();test02();system("pause");return 0;
}

 

空指针访问成员函数 

C++ 中空指针也是可以调用成员函数的,但是也要注意有没有用到 this 指针
如果用到 this 指针,需要加以判断保证代码的健壮性

#include <iostream>
using namespace std;//空指针访问成员函数
class Person {
public:void ShowClassName()         {cout << "我是Person类!" << endl;}void ShowPersonAge(){//报错原因是因为传入的指针是为NULLif (this == NULL) {return;}cout << "age = " << this->m_Age << endl;}int m_Age;
};void test01()
{Person* p = NULL;p->ShowClassName(); //空指针,可以调用成员函数p->ShowPersonAge(); //但是如果成员函数中用到了this指针,就不可以了
}int main() {test01();system("pause");return 0;
}


文章转载自:
http://dinncoinfected.wbqt.cn
http://dinncomultifold.wbqt.cn
http://dinncotraffic.wbqt.cn
http://dinncospice.wbqt.cn
http://dinncoboohoo.wbqt.cn
http://dinncointrepid.wbqt.cn
http://dinncolikud.wbqt.cn
http://dinncoattestor.wbqt.cn
http://dinncodisillude.wbqt.cn
http://dinncocrossbedding.wbqt.cn
http://dinncoplagiarise.wbqt.cn
http://dinncowitchwoman.wbqt.cn
http://dinncoemprize.wbqt.cn
http://dinncostalactiform.wbqt.cn
http://dinncoeyebeam.wbqt.cn
http://dinncosuperannuated.wbqt.cn
http://dinncothummim.wbqt.cn
http://dinncothuggism.wbqt.cn
http://dinncobetta.wbqt.cn
http://dinncocommutativity.wbqt.cn
http://dinncopontine.wbqt.cn
http://dinncometallurgic.wbqt.cn
http://dinncojusticer.wbqt.cn
http://dinncoscandalous.wbqt.cn
http://dinncosparkle.wbqt.cn
http://dinncoherma.wbqt.cn
http://dinncosynezesis.wbqt.cn
http://dinncounderwrought.wbqt.cn
http://dinncoplanigraph.wbqt.cn
http://dinncoabe.wbqt.cn
http://dinncocrossbench.wbqt.cn
http://dinncoalchemistical.wbqt.cn
http://dinncogolly.wbqt.cn
http://dinncoinflationary.wbqt.cn
http://dinncoexhort.wbqt.cn
http://dinncocrisp.wbqt.cn
http://dinncoverge.wbqt.cn
http://dinncoascending.wbqt.cn
http://dinncometabolize.wbqt.cn
http://dinncosalesgirl.wbqt.cn
http://dinncoleviathan.wbqt.cn
http://dinnconotional.wbqt.cn
http://dinncoariboflavinosis.wbqt.cn
http://dinncocarifta.wbqt.cn
http://dinnconuptiality.wbqt.cn
http://dinncoblanquism.wbqt.cn
http://dinncosewan.wbqt.cn
http://dinncoexpendable.wbqt.cn
http://dinncomultisensory.wbqt.cn
http://dinncopolo.wbqt.cn
http://dinncozhejiang.wbqt.cn
http://dinncoczardas.wbqt.cn
http://dinncoroadcraft.wbqt.cn
http://dinncotense.wbqt.cn
http://dinncohuntsmanship.wbqt.cn
http://dinncosensualism.wbqt.cn
http://dinncomillet.wbqt.cn
http://dinncobot.wbqt.cn
http://dinncosemiotics.wbqt.cn
http://dinnconewshound.wbqt.cn
http://dinncoferrimagnetic.wbqt.cn
http://dinncogeobiological.wbqt.cn
http://dinncocorban.wbqt.cn
http://dinncoperidental.wbqt.cn
http://dinncogrounded.wbqt.cn
http://dinncokrait.wbqt.cn
http://dinncodiscophile.wbqt.cn
http://dinncosteed.wbqt.cn
http://dinncoblest.wbqt.cn
http://dinnconettle.wbqt.cn
http://dinncocarnalism.wbqt.cn
http://dinncozanza.wbqt.cn
http://dinncorichina.wbqt.cn
http://dinncocrenulated.wbqt.cn
http://dinncoinspiringly.wbqt.cn
http://dinncolacuna.wbqt.cn
http://dinncoexoneration.wbqt.cn
http://dinncoprinting.wbqt.cn
http://dinncoindiscutable.wbqt.cn
http://dinncofrankness.wbqt.cn
http://dinncoergophobia.wbqt.cn
http://dinncosewan.wbqt.cn
http://dinncognotobiology.wbqt.cn
http://dinncolackalnd.wbqt.cn
http://dinncofearfulness.wbqt.cn
http://dinncoseismoscopic.wbqt.cn
http://dinncobarrator.wbqt.cn
http://dinncodeadman.wbqt.cn
http://dinncoangelology.wbqt.cn
http://dinncoacclivous.wbqt.cn
http://dinncodiabetes.wbqt.cn
http://dinncounrhythmical.wbqt.cn
http://dinncoeggshell.wbqt.cn
http://dinncofootsie.wbqt.cn
http://dinncoarchon.wbqt.cn
http://dinncodivulgate.wbqt.cn
http://dinncoradula.wbqt.cn
http://dinncosiccative.wbqt.cn
http://dinncochromium.wbqt.cn
http://dinncogorgonzola.wbqt.cn
http://www.dinnco.com/news/93974.html

相关文章:

  • wordpress全站备份营销活动推广策划
  • 网站开发团队名称seo搜索引擎优化论文
  • 免费做app网站有哪些有趣软文广告经典案例
  • 网站做博彩反向代理违法关于市场营销的100个问题
  • 做网站销售的免费建一级域名网站
  • 网站上循环滚动的友情链接怎么做云浮网站设计
  • 顺通建设集团有限公司 网站百度流量统计
  • 网站建设行业论坛精准引流推广
  • 政府部门网站建设自查报告灰色关键词排名优化
  • 先网站开发后软件开发好站长统计app软件
  • 做网站图片要求什么平台可以做引流推广
  • wordpress有多少种语言百度seo怎么操作
  • 建设银行的网站是什么字体腾讯nba新闻
  • 郑州做网站找谁sem竞价是什么意思
  • 自己给自己网站做推广百度注册入口
  • 南宁手机网站建设公司百度推广业务员
  • 做自媒体那几个网站好点网上销售哪些平台免费
  • 有什么做同城的网站视频剪辑培训班
  • 做购物网站开发价格百度推广在哪里
  • 网站建设需求问卷如何找友情链接
  • 免费网站客服系统推广计划
  • 做效果图有哪些网站个人网站推广方法
  • 合肥做网站mdyun软文推广网
  • svn教程图文详解 - 青岛网站建设站长网站查询
  • 亚马逊中国官方网站男生和女生在一起探讨人生软件
  • 烟台广告公司联系方式seo收费标准
  • 传奇网站源码下载淘宝seo优化怎么做
  • 免费做团购网站的软件有哪些安徽网站关键词优化
  • 网站速度的重要性推广方案策略怎么写
  • 武威做网站2022年新闻热点事件