#ifndef _HEAD_H_

#definde _HEAD_H_

class NameClass{

}; 冒号别忘记

#endif

::域名解析符      

返回值类型 类名::方法名{.....}

 

Point.h

 
  
  1. #ifndef _POINT_H_ 
  2. #define  _POINT_H_ 
  3. class Point{ 
  4.  
  5. public : 
  6.  
  7.     Point(); 
  8.     ~Point(); 
  9.     int getX(){return x;}; 
  10.     int getY(){return y;}; 
  11.     Point(int , int ); 
  12. private: 
  13.     void setX(int ); 
  14.     void setY(int ); 
  15.     int x; 
  16.     int y; 
  17. }; //不能落下分号; 
  18. #endif // _POINT_H_ 

Point.cpp

 
  
  1. #include"Point.h" 
  2.  
  3. #include <iostream> 
  4.  
  5. using namespace std; 
  6.  
  7.  
  8. Point::Point(){}; 
  9.  
  10. Point::Point(int x, int y){ 
  11.     this->x = x; 
  12.  
  13.     this->y= y; 
  14.  
  15.  
  16. Point::~Point(){ 
  17.  
  18.     cout<<"Point Deconstructor"<<endl
  19.  
  20.  
  21. void Point::setX(int x){ 
  22.  
  23.     this->x  = x; 
  24.  
  25. void Point::setY(int y){ 
  26.     this->y = y; 
  27.