Class
{
Void SS (){**************};
}
Class A has the member function SS ();
The following operations can be performed:
A *;
A * B = NULL;
A * c = new ();
A-> SS ();
B-> SS ();
C-> SS ();
The access to SS () is successful. The reason is that SS () does not retrieve the member variables in Class A, or no member variables in Class A and SS () are not virtual functions.
When Class A is changed to the following:
Class
{
Int COUNT = 100;
Void SS (){*************};
}
The above operations can also be successful in the face of SS (), Because SS () does not retrieve the member variable in Class A or SS () is not a virtual function.
When Class A is changed to the following:
Class
{
Int COUNT = 100;
Void SS () {int CCC = count ;};
}
Only a * c = new A () can be retrieved from the above SS (); otherwise, the crash error may occur, because the new function is not used, the member variable count is not created (initialized), but is declared. Therefore, an error is reported during access. This is the same as the existence of virtual functions in Class A, because if Class A has virtual functions, Class A will save a pointer to the list of virtual functions, if it is not new, the function pointer cannot be initialized. Therefore, a crash error occurs, especially when you need to access a virtual function.