2017 concepts title

Fill in the blank

  1. If the operating environment can each execute a statement, but there are many statements need to be performed, then the curly braces {} enclosed , constituting a block of statements ;
  2. Scope identifier has local scope , the function prototype scope , class scope , namespace scope ;
  3. With initialization statement string "schedule" initialize an array of characters;
    char s[] = { "schedule" };
    char s[] = "schedule";
    char s[] = { 's', 'c', 'h', 'e', 'd', 'u', 'l', 'e', '\0' };
  1. Which of operator must reload member function: assignment operator '=' , remove the standard operator "[]" , the member access operator "->" and functional operators "()"

What is the "else swing" problem, illustrated

C ++ provisions else with the closest match if not yet matched, sometimes indented properly, and if the match does not as intended. E.g:

    if(x > 0)
        if(x < 3)
            /****/
    else
        /***/

Wherein the matching else is "x <3" is if, in the x> when entering else = 3, rather than x <= 0 else enters.

Function templates and function overloading differences and relations

the difference

  1. Function template itself does not generate any compiled object code, generated only by the example of the template generates object code, and function overloading generates object code;
  2. Function template is referenced multiple source files, along with the body of the function should be together in header files, not like a normal function that only the declarations in the header file, but overloaded functions when you can declare and define respectively, on the head files and source files;
  3. Function pointer points to an instance only the template, the template can not point to itself, but may be directed to the overloaded;

contact

From the correlation function is a function template to produce the same name, the compiler overloaded method calls the corresponding function, the function template itself can be overloaded in a variety of ways.

Virtual functions and effect of the difference between a pure virtual function, both

Two different forms when it was declared, as follows:

    virtual void fun();    // 虚函数
    virtual void fun() = 0;// 纯虚函数

Meanwhile, there is no pure virtual function body, but still allow the base class virtual function is given to achieve, given the even achieved, but also must be overridden by derived classes, or can not be instantiated; contrast, virtual function is a function , but the function body body can be empty.

Role of the two is different. When the abstract class with pure virtual functions, its main role is to establish a common interface to a class family through it, so that they can play a more effective multi-state properties, the abstract class declares a common interface to a class derived class family , and complete a full implementation of the interface, i.e., the function pure virtual function, requires the derived class own definition; primary role of a virtual function is polymorphic runtime implementation, establish contact with the derived class objects through a base class pointer or reference, can be the different objects belonging to different derived class produce different behavior.

Guess you like

Origin www.cnblogs.com/southernEast/p/12468420.html