6-13/6-14/6-15
2013-11-02 15:18
239 查看
//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; }
#include <iostream> //6-14 using namespace std; class Point { public: Point(int x=0,int y=0):x(x),y(y) { count++; } Point(const Point &p):x(p.x),y(p.y) { count++; } ~Point() { count--; } int getX() const { return x; } int getY() const { return y; } static int count; private: int x,y; }; int Point::count=0; int main() { int *ptr=&Point::count; Point a(4,5); cout<<"Point A:"<<a.getX()<<","<<a.getY(); cout<<"Object count= "<<Point::count<<endl; Point::count=100; Point b(a); cout<<"Point B: "<<b.getX()<<", "<<b.getY(); cout<<"Object count="<<*ptr<<endl; return 0; }
#include <iostream> //6-15 using namespace std; class Point { public: Point(int x=0,int y=0):x(x),y(y) { count++; } Point(const Point &p):x(p.x),y(p.y) { count++; } ~Point(){count--;} int getX() const {return x;} int getY() const {return y;} static void showCount() { cout<<" Object count="<<count<<endl; } private: int x,y; static int count; }; int Point::count=0; int main() { void (*funcPtr)()=Point::showCount; Point a(4,5); cout<<"Point A:"<<a.getX()<<", "<<a.getY(); funcPtr(); Point b(a); cout<<"Point B:"<<b.getX()<<","<<a.getY(); funcPtr(); return 0; }
相关文章推荐
- 1,2,3,5,7,8,10,11,12,13,14,15,16,21,22 -》1~3,5,7~8,10~16,21~22
- 13-14-15-16-面向对象、继承、封装、struct和class
- 【在路上】Learn Python The Hard Way 习题心得(ex11,12,13,14,15)
- 180中国跳棋(12)186(13)191(14)196(15)201(16)205(17)209.5(18)
- 常见python错误(4,5,13,14,15,17点不错)
- STM32L PC13当IO口使用驱动LED,PC14,PC15外接晶振,且RTC正常...
- Node与Express开发:13 14 15 16 17 18 章
- 阅读<构建之法>13、14、15、16、17章
- Linux Mint 的国内软件源(支持 Linux Mint 13/14/15)
- java 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,
- STM32 PC13 PC14 PC15 驱动LED配置
- Review_2012_11_13_11_14_11_15_11_16
- Jquery李炎恢——47,48,49验证插件【13】【14】【15】
- STM32的PC13、PC14、PC15用作普通IO口设置方法
- 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10.
- 13-4 14-15 NFS exportfs 客户端bug FTP vsftp
- STM32把PC13、PC14、PC15、PB3、PB4、PA15作为普通IO使用
- 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8
- 素数的判断c++程序设计原理与实践第4章习题11、12、13、14、15
- Fedora 12,13,14,15,16/centOS/redhat EL 使用第三方yum 源