- 14
- 0
- 约8.27千字
- 约 45页
- 2016-11-28 发布于河南
- 举报
C经典绝版课件
* * * * * * class Point { public: int getx() const;//在函数头之后注明const int gety() const; void display( ) const; ... private: int x, y; }; int Point::getx() const //此处的const也是必要的 { return x; } 例2-3 常成员函数 2.3.2类的成员函数-常成员函数 与inline不同的是,const必须在成员函数声明和实现时都指明,即const属于函数原型的一部分而不仅是修饰词。 程序中可以定义常量对象(与普通常量具有相同含义),如: const Point pt; 通过常量对象pt只能调用类的const方法。 例2-4 重载成员函数 #include iostream using namespace std; class myclass { public: void set(){x=10;y=20;z=30;} void set(int xx){x=10;y=20;z=30;} void set(int xx,int yy ){x=xx;y=yy;z=30;} void set(int xx,int
原创力文档

文档评论(0)