The basic concept of c ++ Primer

    c++由c语言衍生而来,最大的特点就是它是一门面向对象的语言,面向过程(c)即需要我们去按照步骤去一步一步写代码,而c++提供的面向对象机制帮助我们更有效更方便的开发。
     1.关键字:根据版本的不同关键字的个数有所不同,c中有我们熟悉的32个关键字,而在c++98这个版本中有63个关键字,很多都是和c中关键字类似,以后遇到会细说
     2.命名空间

The concept: using namespace keyword name identifier localized name to avoid naming conflicts or pollution

Hit space defined manner: namespace N1, a namespace can be nested and can have the same namespace name appears, the compiler at compile time which will be combined into a single name space, and the variable defined in a namespace scope only limited to this namespace.

Namespace in three ways: Nl :: A, B :: the using Nl, Nl the using namespace;
3. Default parameters: default parameters is to specify a default value for the parameter in the function declaration or definition of a function, if not arguments passed by default value.
Category: All default parameters (each parameter has a default value), semi default parameters

  • Note: it is assigned from right to left in a semi-defined default parameters when, in this case passed arguments preferential matching leftmost default parameters.
  • The default parameters can not be defined in function definitions and declarations, preferably in a statement.
    4. overloaded functions: a function similar to the definition of several functions in the same scope, its parameter list (number of parameters, parameter types, the parameter order) must be different in order to constitute overloaded functions.
    Here we must say why in c ++ can constitute a function overloading in c language to die, c the compiler to name the function is added before the function name, c ++ have different naming rules based on different compilers, but is at the same point on the function's parameter list in naming modified, of course, in c ++ project can also add "extern" keyword allows the compiler to compile as c style according to their needs, such as:
    #### extern "C" int Add(int x,int y);where the compiler According to compile a C style.
    5. reference (&): the reference is not new definition of a variable but give some variables play an alias, the variable refers to a common memory space.
    Incorporated function parameters and the return value of the function
  • As the function return value, after leaving the scope of the function, which has been returned to the system stack space, and therefore can not return as a reference space on the type stack. If the reference type returns, the return value must lifecycle unrestricted function (i.e., longer than the life cycle function).
  • It cited as an argument efficiency high participation efficient than pass by value, because there is no open space, but the same reference implementation and hands on the ground floor, that almost pass-by-reference and efficiency, but references than pointers to use them more secure.
  • If you do not want to modify the arguments by const reference modified when passed by reference
  • const int && a = 10; reference is not a multi-stage, called the rvalue references.
    6. inline function: to modify the function called inline inline function, when compiling C ++ compiler will inline function call in place of expansion, there is no function push overhead inline functions to enhance the efficiency of the program running.
    So inline functions and macros similar function when the function, then why the introduction of an inline function? When using the macro function need to bring in all the variables c in brackets, or seek expressions results may differ from expectations, thus increasing the risk of the code, and the second is in macro preprocessing is to be replaced, very convenient debugging, no type detection process, and an inline function is replaced at compile time, so the macro function is relatively safer.
  • Alternatively constant const defined in c ++ using macros, macro function replaced with inline functions.
  • Inline function is the practice space for time, so when the code is very long or when there is recursion does not recommend using inline functions, inline keyword for the compiler is only a suggestion, when it is not suitable as the compiler will inline function ignore inline.
  • inline is not recommended for separate definitions and declarations have file scope when inline functions.
    7.auto keyword (c ++ 11)
    Auto modified keywords compiler automatically pushed its type.
  • auto line must be the same type defining a plurality of variables.
  • auto can not function as a parameter can be defined array
    auto second Usage: for loop-based range
    int arr[]={1,2,3,4,5};
    for(auto & e : arr)
    e*=2;

Guess you like

Origin blog.51cto.com/14239789/2438258
Recommended