C ++ source and header files

In a first example of a class definition as

 

In the name of the header file for the student.h

#include <the iostream>
 the using  namespace STD; 
#include < String .h>
 class Student 
{ 
public : // External Interface 
 void INPUT ( char * PID, char * pname, int A, a float S);
  void Modify ( a float S) { = Score S;}
  // member function member in the class inline function automatically 
 void the display ();
 private : // private member 
char * ID;
 char * name;
 int Age;
float score;
};

 

In the solid student student.cpp member function of the class

#include " student.h "  // class definitions where the header 
void Student :: INPUT ( char * PID, char * pname, int A, a float S) 
{ 
// member functions 
ID = new new  char [strlen ( PID) + . 1 ]; 
strcpy (ID, PID); 
name = new new  char [strlen (pname) + . 1 ]; 
strcpy (name, pname); 
Age = A; 
Score = S; 
} 
void Student :: the display () 
{ 
cout << "the above mentioned id: " << endl << the above mentioned id; // although outside the class member functions can still access the private members 
cout << " name: " << name << endl; 
cout << " Age: " << << Age endl; 
COUT << " Score: " << Score << endl; 
}

 

Two specifications for .h and .cpp files

https://www.cnblogs.com/mathyk/p/10921843.html

The three classes are defined and implemented on the benefits of two different files, such as student.h and student.cpp to do so

1. easy to read, manage and maintain separate

2. Place the member function in the class and outside the class, at compile time is not the same meaning

3. For software developers, they can provide some of the program to the user interface module, without exposing the source code

4. The class definition in header files, for later use not have to define, only one command to include the header, rewriting code.

5. facilitate the development of large software division team of

Guess you like

Origin www.cnblogs.com/theda/p/11888367.html