Here is a header file people.h, this header file has a class people, the class has an implementation of the method SayHello ();
1 class people{23public:4 void SayHello (); 5 };
Next, the source file implements the people SayHello method for printing a sentence;
#include <iostream>"people.h"usingnamespace std; void People::sayhello () { cout<<"Hello world! "<<Endl;}
Finally, the main function of the file, the main new people object, and called his SayHello object to print a word; 1 #include <iostream>
1#include <iostream>2#include"people.h"3 using namespacestd;4 5 //class people{6 //7 //Public :8 //void SayHello () {9 //cout<< "Hello world!" <<endl;Ten // } One //}; A - intMain () { -People *p =Newpeople (); the //call the SayHello method of the object -P->SayHello (); - - /*Delete objects that are not used*/ + delete p; - return 0; +}
In fact, the object-oriented mechanism of C + + and other object-oriented programming languages, the logic is the same, but there may be some grammatical differences, that's all.
Object-oriented for C + +