欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: C++語言具有靜態數據和靜態成員函數的Point類 [打印本頁]

作者: daming    時間: 2014-12-30 01:59
標題: C++語言具有靜態數據和靜態成員函數的Point類
本帖最后由 daming 于 2014-12-30 02:15 編輯


  1. #include<iostream>
  2. using namespace std;
  3. class Point                           //point類定義
  4. {
  5. public:                               // 外部接口
  6. Point(int xx=0,int yy=0){X=xx;Y=yy;countP++;};
  7. Point(Point&);                    //拷貝構造函數
  8. ~Point(){countP--;};
  9. int GetX(){return X;}
  10. int GetY(){return Y;}
  11. static void GetC(){cout<<"Object id="<<countP<<endl;}   // 靜態函數成員
  12. private:
  13. int X,Y;
  14. static int countP;               //靜態數據成員聲明
  15. };
  16. int Point::countP=0;                 //靜態數據成員初始化
  17. Point::Point(Point &p)
  18. {
  19. X=p.X;
  20. Y=p.Y;
  21.     countP++;
  22. }

  23. void main()                        //主函數實現
  24. {
  25. Point A(4,5);                  //定義對象A
  26. cout<<"Point A,"<<A.GetX()<<", "<<A.GetY();
  27. A.GetC();                     //輸出對象號,對象名引用  "."
  28. Point B(A);
  29. cout<<"Point B,"<<B.GetX()<<", "<<B.GetY();
  30. Point::GetC();                //類名引用  "::"
  31. }
復制代碼







歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1