zoukankan      html  css  js  c++  java
  • 6-13/6-14/6-15

    //6-13
    #include<iostream> using namespace std; class Point { public: Point(int x=0,int y=0):x(x),y(y){} int getX() const {return x;} int getY() const {return y;} private: int x,y; }; int main() { Point a(4,5); Point * p1=&a; int (Point::*funcPtr)() const=&Point::getX; cout<<(a.*funcPtr)()<<endl; cout<<(p1->*funcPtr)()<<endl; cout<<a.getX()<<endl; cout<<p1->getX()<<endl; return 0; }
     1 #include <iostream>
     2 //6-14
     3 using namespace std;
     4 
     5 class Point
     6 {
     7 public:
     8     Point(int x=0,int y=0):x(x),y(y)
     9     {
    10         count++;
    11     }
    12     Point(const Point &p):x(p.x),y(p.y)
    13     {
    14         count++;
    15     }
    16     ~Point()
    17     {
    18         count--;
    19     }
    20     int getX() const
    21     {
    22         return x;
    23     }
    24     int getY() const
    25     {
    26         return y;
    27     }
    28     static int count;
    29 private:
    30     int x,y;
    31 };
    32 int Point::count=0;
    33 int main()
    34 {
    35     int *ptr=&Point::count;
    36     Point a(4,5);
    37     cout<<"Point A:"<<a.getX()<<","<<a.getY();
    38     cout<<"Object count= "<<Point::count<<endl;
    39     Point::count=100;
    40     Point b(a);
    41     cout<<"Point B: "<<b.getX()<<", "<<b.getY();
    42     cout<<"Object count="<<*ptr<<endl;
    43 
    44     return 0;
    45 }
     1 #include <iostream>
     2 //6-15
     3 using namespace std;
     4 
     5 class Point
     6 {
     7 public:
     8     Point(int x=0,int y=0):x(x),y(y)
     9     {
    10         count++;
    11     }
    12     Point(const Point &p):x(p.x),y(p.y)
    13     {
    14         count++;
    15     }
    16     ~Point(){count--;}
    17     int getX() const {return x;}
    18     int getY() const {return y;}
    19 
    20     static void showCount()
    21     {
    22         cout<<" Object count="<<count<<endl;
    23     }
    24 private:
    25     int x,y;
    26     static int count;
    27 };
    28 
    29 int Point::count=0;
    30 
    31 int main()
    32 {
    33     void (*funcPtr)()=Point::showCount;
    34 
    35     Point a(4,5);
    36     cout<<"Point A:"<<a.getX()<<", "<<a.getY();
    37 
    38     funcPtr();
    39 
    40     Point b(a);
    41     cout<<"Point B:"<<b.getX()<<","<<a.getY();
    42     funcPtr();
    43 
    44     return 0;
    45 }
  • 相关阅读:
    苹果新政,禁止开发者在App中加入检查更新功能
    Xcode 的正确打开方式——Debugging(转)
    AlertView + Block 的使用
    iOS 中Window优先级的问题
    iOS加载启动图的时候隐藏statusbar + 指定启动图显示多少秒
    eclispe+axis2+webservice入门
    Eclispe远程调试tomcat设置
    华为入职培训小计
    Java面试题总结 from Baidu 网易 阿里
    使用MyEclipse 9.0 创建 struts2 的HelloWorld 工程
  • 原文地址:https://www.cnblogs.com/orangebook/p/3403794.html
Copyright © 2011-2022 走看看