C++关键字及说明解释

上传人:hs****ma 文档编号:543437235 上传时间:2023-04-23 格式:DOC 页数:23 大小:63KB
返回 下载 相关 举报
C++关键字及说明解释_第1页
第1页 / 共23页
C++关键字及说明解释_第2页
第2页 / 共23页
C++关键字及说明解释_第3页
第3页 / 共23页
C++关键字及说明解释_第4页
第4页 / 共23页
C++关键字及说明解释_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《C++关键字及说明解释》由会员分享,可在线阅读,更多相关《C++关键字及说明解释(23页珍藏版)》请在金锄头文库上搜索。

1、 C+核心词asm ato bdcastba_ypedboolbreak casecath hrclsconsttccontinuedefaut delete o double ynamic_cast ee enum excepexplicit xter flefially foatf fin gotif inline itlnmtabe nmspae new oprator riat protctd public eiter renterpret_cas renshort sined sief satic sttc_c struct wi mpte his thrwtey tye_fo ty

2、e tyeid typename non unsignedusin vrt vovolilewchat whie (1)asmasm已经被_asm替代了,用于汇编语言嵌入在C/C+程序里编程,从而在某些方面优化代码.虽然用asm核心词编译时编译器不会报错,但是asm模块的代码是没故意义的.(2)auo 这个这个核心词用于声明变量的生存期为自动,即将不在任何类、构造、枚举、联合和函数中定义的变量视为全局变量,而在函数中定义的变量视为局部变量。这个核心词不怎么多写,由于所有的变量默认就是ato的。(3)bad_cst,onst_cst,dynamcst,reinterpret_cst,static

3、_cas有关异常解决的,还不是太理解.(4)ba_tyeid也是用于异常解决的,当teid操作符的操作数typid为Nul指针时抛出(5)bool不用多说了吧,声明布尔类型的变量或函数.(6)br跳出目前循环.The break statt teminas he ecio f theneres closing o rcnditional satement in hich itappr. (7)casesitch语句分支.Labls tha appear fter e ce kyrd cannot aloapea otsde a witch saemnt(8)cth,thow,try都是异常解决

4、的语句,Thetry, throw, an achtatements implemn eption anlin.(9)cr声明字符型变量或函数.(10)class声明或定义类或者类的对象.The clss kewor crs aclas typ or define an object of a clsstyp.(11)nst被cost修饰的东西都受到强制保护,可以避免意外的变动,能提高程序的强健性。它可以修饰函数的参数、返回值,甚至函数的定义体。 作用: 1.修饰输入参数 a对于非内部数据类型的输入参数,应当将“值传递”的方式改为“const引用传递”,目的是提高效率。例如将voi F( a)

5、 改为void Fun(cons A)。 .对于内部数据类型的输入参数,不要将“值传递”的方式改为“nst引用传递”。否则既达不到提高效率的目的,又减少了函数的可理解性。例如voduc(t ) 不应当改为void Fuc(onstint&x)。2.用const修饰函数的返回值 a如果给以“指针传递”方式的函数返回值加nst修饰,那么函数返回值(即指针)的内容不能被修改,该返回值只能被赋给加const修饰的同类型指针。如对于:onst hr * GStin(vd); 如下语句将浮现编译错误: cha *str = GeSing();/canno covert from cnst char * t

6、o har ;对的的用法是: const har *str= GetSring(); b如果函数返回值采用“值传递方式”,由于函数会把返回值复制到外部临时的存储单元中,加ost修饰没有任何价值。 如不要把函数intGetnt(oid) 写成const int etI(vid)。.ost成员函数的声明中,cons核心词只能放在函数声明的尾部,表达该类成员不修改对象. 阐明:const ye ; /修饰m为不可变化 示例: typed char * pStr; /新的类型St; carsrn=abc;car*1 =trin; p1+; /对的,上边修饰的是*p,p1可变 cont pSt p2 =

7、 string; p2+; /错误,上边修饰的是p2,p不可变,*p可变 同理,const修饰指针时用此原则判断就不会混淆了。 const nt value; /*vlue不可变,vlue可变 it* cons vlu; /alue不可变,*vle可变 cont(int *) value;(int *)是一种t,vale不可变,*value可变/逻辑上这样理解,编译不能通过,需要tydef int ewTp;cos int cnstalue;/*vale,valu都不可变(2)coine结束目前循环,开始下一轮循环Fe asfe oontrol to h orolln exprson of t

8、e smallestencsg o, or, o whileloop. (13)dfaltswitch语句中的默认分支.e he constt math the contants n the caslabel;adfal labl setCorol irasered tothe dfaultlabel(1)eee常常用于动态内存分派的语句,ealloatesaloc omry. (15)do在dwhile循环构造中开始循环体Exctes a stem repeatedyuntil the spifie ermnation cnditi (he expeson) vls t ero()dble声

9、明双精度变量或函数.(17)le条件语句否认分支(与if连用).(18)eu声明枚举类型.he name o a eumeraor is tretda csta nd must be niqu withi th scope wre th m deie (19)expicitexpli重要用于 修饰构造函数,使得它不用于程序中需要通过此构造函数进行 隐式 转换的状况,避免不必要的隐式转化;指定此核心字,需要隐式转换方可进行的程序将会不能通过 而可通过强制转换使它没有用This keywrd is draion spifier ttcn onlbe pplied -cascstrto declar

10、ationAn expiit cotrtor cat ta prt in implicit covrsionIt can onybe use to exlicil construct n bject. (0)exoMSDN只说Theexpot keywor isnt uportd o tles.一种导出语句吧(2)etrnexter 意为“外来的”它的作用在于告诉编译器:有这个变量,它也许不存在目前的檔中,但它肯定要存在于工程中的某一种源文献中或者一种Dl的输出中。声明变量是在其他文献中声明(也可以看做是引用变量)Objets and variables declareds eern deca

11、reanobjectha s defidianher transion unitr i an ecloig coeas hvingexernal lnkge.(2)lse,trboo类型的两个枚举值(23)floa声明浮点型变量或函数.(24)fo一种循环语句(可意会不可言传)sethe for statementto consrutlops ha must exeue speciiednumbr of i.(25)end声明友元函数或者类.Th fekywr lls a funcion or clss to in acs to he rivate adprotectd memrs f a c

12、ls. (26)goto无条件跳转语句Perfomsan conditioal transfr f contro o the aed al. (27)if条件语句Conrols codiional banchin常与else一起用()inline声明定义内联函数,编译时将所调用的代码嵌入到主函数中.Th nlinpeciersinsrt th compil o isrt a pyof thefuntion odyinteach ace th fucto isalled.(2)i声明整型变量或函数.(0)lg声明长整型变量或函数.(31)mtablemulbe的中文意思是“可变的,易变的”,跟cnsant(既+中的cost)是反义词。在C中,mutable也是为了突破cnst的限制而设立的。被muble修饰的变量,将永远处在可变的状态,虽然在一种co

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号