The post toward to figure out my confusion of the function point:
http://ly4cn.cnblogs.com/archive/2006/03/13/349180.html
The reason for the existing of the function array or function pointer: when the application require many similar functions, which have the same return type and parameters, toward the different input data of same type, the above solution can make the program elegant and efficient.
void test1(){}
void test2(){}
//function pointer
//invoke: mptr();
void (* mptr)() = &test1;
//function array
//invoke: m[1]();
void (* m[])() = {test1,test2};
1. References
Pointers are directly supported without restrictions in C, C++, Pascal and most assembly languages. They are primarily used for constructing references, which in turn are fundamental to constructing nearly all data structures, as well as in passing data between different parts of a program.
C++ references differ from pointers in several essential ways (depends on the implementation of the compiler):
- It is not possible to refer to a reference object directly after it is defined; any occurrence of its name refers directly to the object it references.
- As a consequence of the first point, neither arithmetic, casts, nor any other operation can be performed on references except copying their binding into other references.
- Once a reference is created, it cannot be later made to reference another object; we say it cannot be reseated. This is often done with pointers.
- References cannot be null, whereas pointers can; every reference refers to some object, although it may or may not be valid.
- References cannot be uninitialized. Because it is impossible to reinitialize a reference, they must be initialized as soon as they are created. In particular, local and global variables must be initialized where they are defined, and references which are data members of class instances must be initialized in the initializer list of the class's constructor.
If the star '*' stands at the left of the statement, it's refer to the definition of the pointer, whereas if the star '*' stands at the right, it's refer to evaluation of the following variable.


2 comments:
what do you mean by "It is not possible to refer to a reference object directly after it is defined" ?
and the meanings of the PS? I don't understand it.
Post a Comment