C++ Notes

1.the difference of "string str=null;" and "tring str="";"

string str=null just declare the variable str,which points to a null,and don't allocate memory.

string str="" has allocated memory and str pointed to this space,which contains a "" character.

2.the difference of null and nullptr

null is a int type variable;

nullptr is a null pointer;

3.strange things

1)when you access the undefine space in string,it will not throw exception

example:

string str="aa";
cout<<str[5];

//run this code,there will be no exceptions,but the value of str[5] may be undefined.

4.inline function

The inline declaration can raise the efficiency in program.when you call a inline function,the complier will copy the inline function body to the place where calls the function.and allocating memory for the local variables in this function,the input arguments and return value will be reflected into this memory.

advantage:

(1) Just like the macro function,the inline function will be expanded in the called place,which omits those steps of ,pushing arguments into the stack,create and recycle the stack frame,and return values,

(2) When expand code,the inline function will do security check and automatic type conversion.

(3) When you declare a funtion in a class,it will be transformed to a inline function automatically.

(4) It could be debug when inline funtion is running.

disadvantage:

(1) code bloat

Inline function brings remarkable improvement in the excuting efficiency,which is a typical case of exchange time with space.As a result of inline function copy the code to the call place,it will expand the memory comsume in a program.

(2) It is not  determinded by coder

The inline keyword just a suggestion to the complier,the complier will determind whether the funtion inline or not.

Matters need attention:

(1) we can not call a inline function by pointer,because,if you want to call a inline function by a pointer,it must acquire the address of the inline function,so we must creaete a entity of this funtion, the inline will defeat.

(2) we would better not define a constructor and destructor as a inline function,because,there are amount of code behind these funtion.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值