类成员方法的内联写法

来源:互联网 发布:网络硬盘录像机怎么用 编辑:程序博客网 时间:2024/05/16 18:02
#include <iostream>using namespace std;class point{public:    //内联写法point(int _x=0, int _y=0):x(_x),y(_y){//与类重名,没有返回值这个属性,只有构造函数才能初始化/*.......*/}void print() const {   //const 修饰this指针// set(1,2);是不行的,const里不能有非const函数cout << "(" << x << ","  << y << ")" << endl;}void set(int _x, int _y){x = _x; //this->x=_xy = _y;cout << "this\t@" << this << endl;}private:int x;int y;};int main(){point p4(20,20);p4.set(5,5);    //p4是调用对象p4.print();cout << "p4\t@" << &p4 << endl;}

原创粉丝点击