Class definition: class definition, can know the size of the class
Implementation of the class:
Declaration of the class: the declaration of the class, indicating that, with this class, the compilation does not go wrong
C + + does not make "detach interface from implementation" very well. The definition of class not only describes the class interface, but also includes a full implementation prologue. Such as:
Class Person
{
Public
Person (const string& name,const dateg& birthday,const address& addr);
String name () const;
String birthDate () const;
String address () const;
....
Private
String thename;
Date thebirthdate;
Address theaddress;
};
The person here cannot be compiled because the compiler does not see the definition of string,date and address. Such a definition is usually provided by the # include indicator, so there is probably something like this at the top of the person definition file:
#include <string>
#include "date.h"
#include "Address.h"
However, this creates a compilation dependency between the person definition file and its included files. If one of these header files is changed, or if any of the other header files that the header files depend on change, then each file containing the person class will have to be recompiled, and any files that use the person class must be recompiled. This usually causes disaster for large projects.
Workaround:
Consider adding a predecessor declaration to remove the header files included with # include:
Class date;//front-facing declaration
Class address;//front-facing declaration
Class person{
Public
Person (const std::string& name, const date& birthday, const address& addr);
std::string name () const;
std::string birthDate () const;
std::string address () const;
...
Private://optional, write not write
String thename;
Date thebirthdate;
Address theaddress;
};
With this approach, the coupling can be eliminated, the class person has no dependency on the class date, and the person's client is recompiled only when the person interface is modified.
But there's a problem with this approach:
int main () { int x; Person P (params);}
When the compiler sees the definition of x, it knows how much memory must be allocated before it can tolerate the next int. But when the editor sees the definition of P, how do you know how big a person is? The only way to do this is to ask for the definition of class, but if the class definition does not list the implementation details (not knowing the implementation details of class date, etc.)
C + + minimizes compilation relationships between files