C ++ cow brush off questions day23

1.C ++ or C inside annotated with two types / * ------ * /, the other is a single line can be // -----  

2. destructor name and the name of the same class, just add a bit inversion function name in the symbol ~, to distinguish it from the constructor. It can not take any parameters, no return value (void type including). Only one destructor, can not be overloaded. If the user does not write a destructor, the compiler automatically generates a default destructor (even custom destructor, the compiler always a destructor will be synthesized for us, and if the custom destructor the compiler first calls when executed from the destructor defined recall synthesized destructor), it does not perform any operation. So many simple without explicit class destructor.

3.

The main function is to match functor STL algorithm, is used alone functor is relatively small.
Functor (functors) employed in the name of the C ++ function object is a standard (function objects). Function is mainly required for the simulation of the STL algorithm, although the function pointer as a parameter, although the algorithm may be, but does not meet STL function pointer abstract requirements, and can not meet the software building blocks - not function pointer with other components and STL resulting in a more flexible and change. Functor is essentially a heavy-duty class operator (), the behavior of objects to create a similar function.

For overloaded () operator class, a similar procedure may be implemented function call, so called functor functor objects actually occupies only 1 byte, because there is no internal data members, only an overloaded method only. Actually implement similar functionality by transfer function pointer, but for use with internal STL, he provides features functor.

Examples are as follows:

struct node
{
bool operator()(const int a,const int b) const
{
return a<b;
}
bool operator>(const int a,const int b) const
{
return a>b;
}
};

We can be invoked by calling the object or function temporary class. Is essentially a function pointer, the function pointer can not be combined with the abstract STL, so it appears functor this stuff.

4. Visibility refers to where to call, to call is visible, when referring to the existence of initialization when to release, on a range of text, a life cycle

Visibility internal static class is defined within the range of its functions (i.e., '{}' of) , but its presence is run until the end of

Passing an array, the length may be omitted arguments, parameters, the first dimension may be omitted, but the rest must be specified length

5.else always paired with the same scope recently missed and paired else if. Do not understand simple.

6. class make it clear that, after executing the constructor to initialize the correct virtual function table, so call the virtual function in the constructor virtual function table when this time has not been initialized properly, call a function in this class, namely, static type corresponding to the function, in the same way destructor virtual function call can not, because the virtual function table has been destroyed

7.

Guess you like

Origin www.cnblogs.com/Tonarinototoro/p/11585504.html