c++关键字及说明解释

上传人:小** 文档编号:89043822 上传时间:2019-05-16 格式:DOC 页数:20 大小:89KB
返回 下载 相关 举报
c++关键字及说明解释_第1页
第1页 / 共20页
c++关键字及说明解释_第2页
第2页 / 共20页
c++关键字及说明解释_第3页
第3页 / 共20页
c++关键字及说明解释_第4页
第4页 / 共20页
c++关键字及说明解释_第5页
第5页 / 共20页
点击查看更多>>
资源描述

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

1、 C+关键词asm auto bad_cast bad_typeid bool break case catch char class const const_cast continue default delete do double dynamic_cast else enum except explicit extern false finally float for friend goto if inline int long mutable namespace new operator private protected public register reinterpret_cas

2、t return short signed sizeof static static_cast struct switch template this throw true try type_info typedef typeid typename union unsigned using virtual void volatile wchar_t while (1)asmasm已经被_asm替代了,用于汇编语言嵌入在C/C+程序里编程,从而在某些方面优化代码.虽然用asm关键词编译时编译器不会报错,但是asm模块的代码是没有意义的.(2)auto 这个这个关键词用于声明变量的生存期为自动,即

3、将不在任何类、结构、枚举、联合和函数中定义的变量视为全局变量,而在函数中定义的变量视为局部变量。这个关键词不怎么多写,因为所有的变量默认就是auto的。(3)bad_cast,const_cast,dynamic_cast,reinterpret_cast,static_cast关于异常处理的,还不是太了解.(4)bad_typeid也是用于异常处理的,当typeid操作符的操作数typeid为Null指针时抛出.(5)bool不用多说了吧,声明布尔类型的变量或函数.(6)break跳出当前循环.The break statement terminates the execution of t

4、he nearest enclosing loop or conditional statement in which it appears. (7)caseswitch语句分支.Labels that appear after the case keyword cannot also appear outside a switch statement. (8)catch,throw,try都是异常处理的语句,The try, throw, and catch statements implement exception handling.(9)char声明字符型变量或函数.(10)class

5、声明或定义类或者类的对象.The class keyword declares a class type or defines an object of a class type.(11)const被const修饰的东西都受到强制保护,可以预防意外的变动,能提高程序的健壮性。它可以修饰函数的参数、返回值,甚至函数的定义体。 作用: 1.修饰输入参数 a.对于非内部数据类型的输入参数,应该将“值传递”的方式改为“const引用传递”,目的是提高效率。例如将void Func(A a) 改为void Func(const A &a)。 b.对于内部数据类型的输入参数,不要将“值传递”的方式改为“c

6、onst引用传递”。否则既达不到提高效率的目的,又降低了函数的可理解性。例如void Func(int x) 不应该改为void Func(const int &x)。 2.用const修饰函数的返回值 a.如果给以“指针传递”方式的函数返回值加const修饰,那么函数返回值(即指针)的内容不能被修改,该返回值只能被赋给加const修饰的同类型指针。 如对于:const char * GetString(void); 如下语句将出现编译错误: char *str = GetString();/cannot convert from const char * to char *; 正确的用法是:

7、 const char *str = GetString(); b.如果函数返回值采用“值传递方式”,由于函数会把返回值复制到外部临时的存储单元中,加const修饰没有任何价值。 如不要把函数int GetInt(void) 写成const int GetInt(void)。 3.const成员函数的声明中,const关键词只能放在函数声明的尾部,表示该类成员不修改对象. 说明: const type m; /修饰m为不可改变 示例: typedef char * pStr; /新的类型pStr; char string4 = abc; const char *p1 = string; p1+

8、; /正确,上边修饰的是*p1,p1可变 const pStr p2 = string; p2+; /错误,上边修饰的是p2,p2不可变,*p2可变 同理,const修饰指针时用此原则判断就不会混淆了。 const int *value; /*value不可变,value可变 int* const value; /value不可变,*value可变 const (int *) value; /(int *)是一种type,value不可变,*value可变 /逻辑上这样理解,编译不能通过,需要tydef int* NewType; const int* const value;/*value,

9、value都不可变(12)continue结束当前循环,开始下一轮循环.Forces transfer of control to the controlling expression of the smallest enclosing do, for, or while loop. (13)defaultswitch语句中的默认分支.None of the constants match the constants in the case labels; a default label is present.Control is transferred to the default labe

10、l.(14)delete经常用于动态内存分配的语句,Deallocates a block of memory. (15)do在do-while循环结构中开始循环体.Executes a statement repeatedly until the specified termination condition (the expression) evaluates to zero.(16)double声明双精度变量或函数.(17)else条件语句否定分支(与 if 连用).(18)enum声明枚举类型.The name of each enumerator is treated as a co

11、nstant and must be unique within the scope where the enum is defined. (19)explicitexplicit主要用于 修饰 构造函数,使得它不用于程序中需要通过此构造函数进行 隐式 转换的情况,防止不必要的隐式转化.;指定此关键字,需要隐式转换方可进行的程序将会不能通过. 而可通过强制转换使它没有用.This keyword is a declaration specifier that can only be applied to in-class constructor declarations. An explici

12、t constructor cannot take part in implicit conversions. It can only be used to explicitly construct an object. (20)exportMSDN只说The export keyword is not supported on templates.一种导出语句吧.(21)externextern 意为“外来的”它的作用在于告诉编译器:有这个变量,它可能不存在当前的檔中,但它肯定要存在于工程中的某一个源文件中或者一个Dll的输出中。声明变量是在其它文件中声明(也可以看做是引用变量).Objec

13、ts and variables declared as extern declare an object that is defined in another translation unit or in an enclosing scope as having external linkage.(22)false, truebool类型的两个枚举值.(23)float声明浮点型变量或函数.(24)for一种循环语句(可意会不可言传).Use the for statement to construct loops that must execute a specified number o

14、f times.(25)friend声明友元函数或者类.The friend keyword allows a function or class to gain access to the private and protected members of a class. (26)goto无条件跳转语句.Performs an unconditional transfer of control to the named label. (27)if条件语句.Controls conditional branching.常与else一起用.(28)inline声明定义内联函数,编译时将所调用的代码嵌入到主函数中.The inline specifiers instruct the compiler to insert a copy of the function body into each place the function is called.(29)int声明整型变量或函数.(30)long声明长整型变量或函数.(31)mutablemutalbe的中文意思是“可变的,易变的”,跟constant(既C+中的const)是反义词。在C+中,mutable也是为了突破const的限制而设置的。被mutable修饰的变量,将永远处于可变的状态,即使在一个co

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

当前位置:首页 > 商业/管理/HR > 管理学资料

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