CPP课件第1章C++概述幻灯片.pptVIP

  1. 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
* There are two problems with the use of preprocessor macros in C++. The first is also true with C: a macro looks like a function call, but doesn’t always act like one. This can bury difficult-to-find bugs. The second problem is specific to C++: the preprocessor has no permission to access class member data. This means preprocessor macros cannot be used as class member functions. To retain the efficiency of the preprocessor macro, but to add the safety and class scoping of true functions, C++ has the inline function. * When you use inline function, the compiler checks to ensure the call is correct and the return value is being used correctly, and then substitutes the function body for the function call, thus eliminating the overhead. (The inline function reduce the time of a function call and thus preserve the efficiency.) The inline code does occupy space, but if the function is small, this can actually take less space than the code generated to do an ordinary function call (pushing arguments on the stack and doing the CALL). 函数原型的作用 C++语言是强类型化语言,任何函数在使用以前必须有该函数的原型说明,以便进行实际参数与形式参数之间的类型匹配检查。 函数返回值的类型和函数参数的类型、个数、次序在函数声明,函数定义和函数调用时必须匹配。 C++语言的编译器执行上述检查能显著减少很多隐藏的错误。 函数原型与C语言的函数类型说明 函数原型是在C语言的函数类型说明(函数声明)的基础上进行扩充后形成的, 它不但说明了函数返回值的类型,还要确定函数参数的类型、个数、次序及缺省值。 1.3.5  带缺省参数的函数 例如:以下函数带有一个缺省值为0的参数。 void myfunc(double d=0.0) { … } myfunc(198.234); // pass an explicit value myfunc( ); // let function use default 缺省参数的例子 void DrawCircle(int x,int y,int r=10); DrawCircle(50,20); DrawCircle(50,100,30); 带缺省参数函数主要由两个作用:简化编程;有利于程序扩充,而不影响原有代码。 1.3.6  函数名重载(overload ) 两或两个以上的函数共享同一个名称,就称为函数名重载。 Overloaded Functions Multiple functions can have the same name with different implementations. 函数重载简化了函数调用工作。 函数重载的例子 #include iostream.h ? //Overload abs( ) three ways ? int abs(int n); long abs(long n); double abs(double n); //prototype is neccessary for C++ compiler 这些都是函数原型 函数重载的例子 main( ) { coutAbsolute value of -10:abs(-10)\n; coutAbsolute value of -10L:abs(-10L)\n; cout

文档评论(0)

精品课件 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档