Const member functions of C ++ class
Double Sales_item: avg_price () Const
{
}
The const keyword indicates that this is a const member function and it cannot modify the member variables of the sales_item class.
If no constructor is defined for a class, the compiler will automatically generate a default constructor for the class to become the "default constructor for synthesis ". In this case, the constructor will not automatically initialize members of the built-in type. For members of the class type, such as string, the default constructor of string is used for initialization.
When you call a copy function, you do not need to consider whether the parameter is not Const. The function is only a copy. The function cannot change the real parameter. The result is that the const object can be passed to the cosnt parameter or non-const parameter. There is no essential difference between the two. It is worth noting that the equivalence of the const parameter mentioned here is only applicable to non-reference parameters. It is not applicable to references and pointers. C ++ primer p229.