码迷,mamicode.com
首页 > 编程语言 > 详细

c++ primer learning point.1

时间:2014-11-16 21:24:45      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   color   ar   os   sp   for   strong   

1.when we wanna share const variables; we use the keyword extern on both its definition and declaration(s):

2.Once initialized, a reference remains bound to its initial object. There is no way to rebind a reference to refer to a different object. Because there is no way to rebind a reference, references must be initialized.

3.Reference is not an object. it only share the address of lvalue.

4.the most important is the understanding of inner ‘reference & pointer‘ mechanism.Its about the address.

bubuko.com,布布扣
keywords--const,it differ with top-level and low-level,[pointer] right-most const is always top-level;if it‘s top-level,it cannot be changed.Reference types is always low-level.

5.Declarations that use type aliases that represent compound types and const can yield surprising results.

bubuko.com,布布扣

For instance, typedef char* pstring is differnt with typedef char *pstring.

6.By implication, a variable that uses auto as its type specifier must have an initializer:

bubuko.com,布布扣

7. always define header guard in .h or .hpp file in case of this file are included twice.

bubuko.com,布布扣

8.subscript of string and vector, subscript is to fetch the value of vector, it cannot add element

bubuko.com,布布扣

9.evaluate/precedence/associate

bubuko.com,布布扣

notify the order of evaluation

10.compound operator 

Each compound operator is essentially equivalent to

a = a op b;

with the exception that, when we use the compound assignment, the left-hand operand is evaluated only once. If we use an ordinary assignment, that operand is evaluated twice: once in the expression on the right-hand side and again as the operand on the left hand. In many, perhaps most, contexts this difference is immaterial aside from possible performance consequences.


11.bubuko.com,布布扣


12.Do not return local object‘s pointers or reference.


13.Name lookup happens before type checking. Local to outter and find the same name of function.


14.
Note

The inline specification is only a request to the compiler. The compiler may choose to ignore this request.

In general, the inline mechanism is meant to optimize small, straight-line functions that are called frequently. Many compilers will not inline a recursive function. A 75-line function will almost surely not be expanded inline.


15.In this constructor there is no constructor initializer list, although technically speaking, it would be more correct to say that the constructor initializer list is empty. Even though the constructor initializer list is empty, the members of this object are still initialized before the constructor body is executed.

16.

The only  difference between using class  and using struct to define a class is the default access level.

As a matter of programming style, when we define a class intending for all of its members to be public, we use struct. If we intend to have private members, then we use class.


 




c++ primer learning point.1

标签:style   http   io   color   ar   os   sp   for   strong   

原文地址:http://www.cnblogs.com/cool-coder/p/4101901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!