1. For the defined function bool Fibon_elem (int pos, int &elem) {}, write Fibon_elem (POS, Elem) when calling, do not need to use & in the call process
But if the function definition is bool Fibon_elem (int pos, int &elem) {}, then if the function needs to be declared, it must be bool Fibon_elem (int, int &), that is, the declaration cannot be omitted at the time &
2. Manipulating a ref and manipulating the object represented by this ref is no different
3. When you define ref, you need to assign a value to ref, and this ref will always represent the object it refers to. A bit similar to the final static variable in Java, it must be assigned at the time of definition and will never be modified.
4. For a const vector,vector[index]=n this sentence is wrong. Good understanding!!
5. When passing the built-in type, do not use the forwarding method, the forwarding mechanism is mainly used for transmitting class object
6. When a function is called, a special area is created in memory called the "program stack". This area provides the storage space for each function parameter and the object defined by the function type. Once the function is complete, the memory is freed.
7. By default, objects allocated by the heap are uninitialized
New Type
New Type (Initial_value)
New Type[length]
Delete Point
Delete [] Point
8. It is incorrect to return a local variable of a function either in the form of point or reference.
By me I test myself, whether it's returning a local variable at point or reference, or even returning a local variable directly, it's all right, there's no syntax error, but there's a compile warning.
However, if you use point, there is an unexpected situation, because the memory of the local variable may have been released!!!
But if you use reference, is normal, do not know is not the test problem???
9. The default value can only be made once, at the function declaration, or at the function definition, but not in two places. For visibility, the default value is generally placed at the function declaration.
By me my own test, the default value can not be specified in two places, this is correct, if all specified, compile error.
But if the default function is specified at the function declaration, there is no problem, when the function is called, arguments can be passed or not passed.
However, the default value function, if specified at the function definition, must be passed when the function is called. Compile an error if you do not pass.
10. If a function returns a const object, the object cannot be assigned a value to a non-const object
11.inline can be placed in the H file or in the CPP file or both H file and CPP file, no error.
12. About overloading
The following code is legal:
void Demooverload (String s)
{
}
void Demooverload (string& s)
{
}
void Demooverload (const string& s)
{
}
void Demooverload (string* s)
{
}
void Demooverload (const string* s)
{
}
The following code is illegal:
void Demooverload (String s)
{
}
void Demooverload (const string s)
{
}
That is, modifying point or reference with Const can be a different function overload, but if const directly modifies the object, it is not a function overload.
13. When a template function is called, you do not need to make a type. This is different from generics.
14. The variable declaration in the header file???
C + + Learning notes (2)