资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,第五章特殊函数和组员,5.1对象组员初始化,类对象能够做其它类数据组员,称为,对象组员。,如:,class A,类名1 组员1;,类名2 组员2;,;,当A类产生对象时要初始化A所有组员,因此会调用A类,函数。,结构,1,第1页,第1页,A类结构函数定义下列:,A:A(参数0),:,组员1(参数1),组员2(参数2),组员n(参数表n),/其它操作,注:假如初始化列表某项参数表为空,则列表中相应项能够省略。,2,第2页,第2页,如有:,class,date,int year,month,day;,public:,;,class,student,int num;string name;,date birthday;,public:,;,则student类结构函数形式为:,student(int n,string s,date d),:num(n),name(s),birthday(d),3,第3页,第3页,若对象B是类A子对象,则在建立A类对象时:,执行B结构函数,(初始化类中其它组员),结构顺序,执行B结构函数,(初始化B数据组员),执行B析构函数,执行A析构函数,析构顺序,注意:1)A产生对象时,先调用对象组员结构函数,初始化对象组员,然后才执行A结构函数,对象组员初始化顺序与这些对象在类A中阐明顺序,,与它们在初始化列表中顺序无关。,4,第4页,第4页,注意:2)A类结构函数中未给出组员对象初始化,组员对象产生时调用无参结构函数,若此时组员所在类中没有无参结构函数则报错!,5,第5页,第5页,找出下面程序错误,更正后分析程序结果(lt5_1b.cpp),class A int x1,y1;,public:,A(int c,int d),x1=c;y1=d;coutA结构!x1y1endl;,;,class B A a;int x2,y2;,public:,B()coutB默认结构!;,B(int c=0,int d=0),x2=c;y2=d;coutB结构!x2y2endl;,;,void main()B b;,A()coutA默认结构endl;,B b(1,2);,B(int c,int d,int x,int y):a(x,y),B b(1,2,10,100);,6,第6页,第6页,练习:给出程序运营结果(lt5_1.cpp),#include,using namespace std;,class Point,int x,y;,public:,Point():x(0),y(0),Point(int a,int b):x(a),y(b),cout结构:x,yendl;,;,class Rectangle,Point a;Point b;,public:,Rectangle(int x,int y,int m,int n):,a(x,y),b(m,n),;,void main(),Rectangle a(1,1,5,5);,b(m,n),a(x,y),7,第7页,第7页,对象组员初始化,8,第8页,第8页,const组员和引用组员初始化,数据组员不能在定义时初始化,数据组员操作语句必须放在组员函数中,引用组员不能初始化为常量引用,const组员和引用组员,必须在结构函数初始化列表中初始化,(lt5_1c.cpp),初始化列表形式结构函数:,A:A(参数0):组员1(参数1),组员2(参数2),9,第9页,第9页,using namespace std;,class example,const int num;,int data;,int,public:,example(int n,int f):num(n),data(f),ref(data),cout结构.endl;,void show(),cout对象中数据是:,num,data,refendl;,;,void main(),int x=1,y=2;,example a(x,y);,a.show();,10,第10页,第10页,定义时使用了static,则组员为静态组员,5.2静态组员,阐明:,1)静态数据组员必须在类体外按照下列格式:,类型 类名:静态组员名=值;,进行初始化,不可在结构函数中初始化,11,第11页,第11页,class Test,static,int x;,int n;,public:,Test(),Test(int a,int b)x=a;n=b;,static,int func()return x;,static,void sfunc(Test&r,int a),r.n=a;,int Getn()return n;,;,int Test:x=25;,静态数据组员初始化,12,第12页,第12页,4、静态组员是类组员不是对象组员,2、static组员所有者是,类,,,被该类所有对象所共有,所有对象均可访问静态组员,。,静态组员仍然遵循public,private,protected访问准则。,3、静态组员不依赖于对象而存在,对象不存在时静态组员已存在,5、,静态组员函数,没有this指针,,,不可直接使用非静态组员,,必须,通过对象(或者指向对象指针),使用非静态组员。,13,第13页,第13页,class Test,static,int x;,int n;,public:,Test(),Test(int a,int b),x,=a;n=b;,static,int func()return,x,;,static,void sfunc(Test,int Getn()return n;,;,int Test:x=25;,类中,任何函数,都能够访问静态组员。,静态组员函数不能直接访问非静态数据组员,能够通过对象来访问。,(int a)n=a;,error:illegal reference to data member Test:n in a static member function.,14,第14页,第14页,7、未定义对象时,能够通过类使用静态组员按下列格式:,类名:静态数据组员名,类名:静态组员函数();,6、静态组员函数不能阐明为虚函数(第8章),15,第15页,第15页,class Test,int n;,public:,Test(),Test(int a,int b)x=a;n=b;,static,int func()return x;,static,void sfunc(Test&r,int a),r.n=a;,int Getn()return n;,;,int Test:x=25;,void main(),cout,Test:,func();,通过类使用静态组员函数,static,int x;,cout,Test:,x();,通过类使用静态组员函数或者数据组员,16,第16页,第16页,class Test,int n;,static,int x;,public:,Test(),Test(int a,int b)x=a;n=b;,static,int func()return x;,static,void sfunc(Test,int Getn()return n;,;,int Test:x=25;,void main(),Test b,c;,b.sfunc(b,58);,cout b.Getn();,cout b.func();,cout c.func();,Test a(24,56);,cout a.func()b.func()c.func()endl;,58,25,25,24,24,24,17,第17页,第17页,class Test,int n;,static int x;,public:,Test(),Test(int a,int b)x=a;n=b;,static int func()n=x+1;return x;,static void sfunc(Test,int Getn()return n;,;,找出下面类定义中错误,并阐明原因,int Test:x=100;,静态组员函数不能直接访问非静态数据组员,静态数据组员必须进行初始化,18,第18页,第18页,1,静态组员函数与类名连用,可通过对象使用,class test,static int x;,int n;,public:,test(int a=0,int b=0)x=a;n=b;,static int func()return x;,int getn()return n;,;,int test:x=25;,void main(),cout,test:,func(),endl;,test b;,cout,b.,func(),endl;,与类名连用,通过对象使用,19,第19页,第19页,2,在没有建立对象之前,静态组员已经存在,class test,static int x;,int n;,public:,test(int a=0,int b=0)x=a;n=b;,static int func()return x;,int getn()return n;,;,int test:x=25;,void main(),cout,test:func(),endl;,test b,c;,cout,b.func(),endl;,20,第20页,第20页,3,静态组员是,类,组员,不是对象,组员,class test,static int x;,int n;,public:,test(int a=0,int b=0)x=a;n=b;,static int func()return x;,int getn()return n;,;,int test:x=25;,void main(),cout,test:func(),endl;,test b,c;,cout,b.func(),endl;,21,第21页,第21页,4,静态组员被类所有对象共享,class test,static int x;,int n;,public:,test(int a=0,int b=0)x=a;n=b;,static int func()return x;,int getn()return n;,;,int test:x=25;,void main(),cout,test:func(),endl;,test b,c;,cout,b.,func(),c.,func(),endl;,22,第22页,第22页,5,静态组员函数不可使用非静态组员,class test,static int x;,int n;,public:,test(int a=0,int b=0)x=a;n=b;,static int func()return,n,;,;,int test:x=25;,void main(),cout,test:func(),endl;,test b,c;,cout,b.func(),c.func(),endl;,错误,23,第23页,第23页,特点:,一旦定义始终存在于内存中,,直到程序结束才释放,复合语句(,用括起来多条语句,)内定义对象只在复合语句内有效,复合语句执行完毕,对象释放内存。,5.2静态组员-静态对象,静态对象是由,static,申明类对象,24,第24页,第24页,class test,int n;,public:,test(int i)n=i;cout结构:nendl;,test()cout析构:nendl;,int getn()return n;,void inc()+n;,;,void main(),cout循环开始endl;,for(int i=0;i2;i+),couti=i时:endl;,test b(3);,b.inc();,coutb.n=b.getn()endl;,cout循环结束endl;,coutmain结束endl;,b,i=0时:,3,4,循环开始,结构:3,b=4,析构4,i=0时:,b,i=1时:,3,4,25,第25页,第25页,class test,int n;,public:,test(int i)n=i;cout结构:nendl;,test()cout析构:nendl;,int getn()return n;,void inc()+n;,;,void main(),cout循环开始endl;,for(int i=0;i2;i+),couti=i时:endl;,test b(3);,b.inc();,coutb.n=b.getn()endl;,cout循环结束endl;,coutmain结束endl;,static,test b(3);,b,i=0时:,3,4,循环开始,结构:3,b=4,i=0时:,i=1时:,i=1时:,5,b=5,循环结束,main结束,析构5,26,第26页,第26页,void main(),cout循环开始endl;,for(int i=0;i2;i+),couti=i时:endl;,test b(3);,b.inc();,coutb.n=“,b.getn()endl;,cout循环结束endl;,coutmain结束endl;,void main(),cout循环开始endl;,for(int i=0;i2;i+),couti=i时:endl;,static,test b(3);,b.inc();,coutb.n=“,b.getn()endl;,cout循环结束endl;,coutmain结束endl;,27,第27页,第27页,注:静态对象结构函数与析构函数调特点:,1、结构函数在代码执行过程中,第一次碰到它变量定义时被调用,但直到整个程序结束之前仅调用一次。,2、析构函数在整个程序退出之前被调用,同样也只调用一次。,即:,碰到定义则调用结构函数,程序结束调用析构函数,结构函数只调用一次,,析构函数也只调用一次,28,第28页,第28页,课程回顾,2一个const对象只能访问,组员函数。,3.设类Test中存在组员static int x,则下列哪种初始化方式是正确(),A.Test:int x=25;B.int x=25;,C.int Test:x=25;D.int Test x=25;,const,C,4.类A中存在公有静态数据组员x,设a和b是类A两个对象,在执行a.x=10之后,b.x 值为(),A.未初始化 B.等于a.x C.等于0 D.随机,B,1.若类组员函数用关键字static进行修饰,这样组员函数称为,。,静态组员函数,29,第29页,第29页,5.关于类静态组员函数描述错误是(),A.在创建对象前不存在,B.能够被非静态组员函数访问,C.能够直接被静态组员函数访问,D.不是对象组员,A,30,第30页,第30页,6.找出下列程序中错误,并阐明原因,#include,class test,private:int x;,public:test(int a)x=a;,void set(int a)x=a;,void get()coutxendl;,main(),const test a(3);,a.set(5);,a.get();,不能改变常对象数据组员值,31,第31页,第31页,5.3友元函数,友元提供应了不同类或者对象组员函数之间、类组员函数与普通函数之间进行数据共享机制。也就是说,经过友元,一个普通函数或者类组员函数能够访问到封装于另一个类中数据,这相称于给类封装开了一个小孔,经过它能够看到类内部一些属性。,假如友元是普通函数或者类组员函数,则称为,友元函数,。友元函数是拥有组员函数一切权利非组员函数。也就是说,友元函数,不是类组员函数,,但能够像组员函数同样直接访问类,私有,组员。,假如友元是一个类,则称为,友元类,,,友元类所有组员函数都为友元函数,。,32,第32页,第32页,友元三种形式:,1、普通函数作一个类友元,2、将a类组员函数作b类友元,3、将一个类a作为另一个类b友元,33,第33页,第33页,一个友元,类,/,函数,/,组员函数,能够,通过对象使用另一个类,私有,组员,。,友元函数能够访问,对象私有组员,公有组员和保护组员,。,友元能够是一个类或函数。,友元需通过对象、对象引用、对象指针来使用类组员。,34,第34页,第34页,在类外对fun函数进行定义,,此时,fun函数不是类组员函数,友元申明能够在类private和public部分,普通友元函数能够通过,对象、对象引用、对象指针,使用对象,私有组员,。,一、普通函数作一个类友元,在,类体内,用,friend,对普通函数fun进行,申明,,则fun成为类友元函数。,35,第35页,第35页,在类体内需要对友元函数进行申明,class point,double x,y;,public:,point(double xi,double yi),x=xi;y=yi;,friend,double dist(point,;,double dist(point&p1,point&p2),double dx=,p1.x-p2.x;,double dy=,p1.y-p2.y;,return sqrt(dx*dx+dy*dy);,在类中申明,但不是组员函数,point&p1,point&p2,友元函数不是类组员函数,没有this指针,因此必须用对象或者引用或者对象指针做参数。,point:,dist(point&p1,point&p2),36,第36页,第36页,class point,double x,y;,public:,point(double m,double n),x=m;y=n;,friend,double dist(point,;,double dist(point,&,p1,point,&,p2),double dx=,p1.,x,-,p2.,x;,double dy=,p1.,y,-,p2.,y;,return sqrt(dx*dx+dy*dy);,void main(),point p1(1.1,2.2),p2(3.3,4.4);,cout dist(,p1,p2,)endl;,37,第37页,第37页,引用做形参和对象做形参区别是什么?,对象做形参,形参对象,内存,,会引起,函数调用,引用做形参,形参,内存,,复制结构函数,对象做形参,形参改变,引起实参改变。,引用做形参,形参改变,引起实参改变,指针做形参也可实现,注意其形式什么?,复制结构,不分派,分派,不调用,会,不会,38,第38页,第38页,class point,double x,y;,public:,point(double m,double n),x=m;y=n;,friend,double dist(point,;,double dist(point,&,p1,point,&,p2),double dx=,p1.,x-,p2.,x;,double dy=,p1.,y-,p2.,y;,return sqrt(dx*dx+dy*dy);,void main(),point p1(1.1,2.2),p2(3.3,4.4);,cout dist(,p1,p2,),*,*,-,-,-,&,&,39,第39页,第39页,假定f()是类A中组员函数,能够在类B中申明,将类A组员函数f()申明为类B友元,申明函数f时需限定该函数f是类A组员函数,并在f中访问B组员时,需通过对象、引用、指针来进行访问。,二、A类组员函数作B类友元,class A,void,f(B,;,class B,friend,void,A:,f(B,;,将A类组员函数f阐明为该类友元,40,第40页,第40页,class Two;,class One,int x;,public:,One(int a):x(a);,int Getx()return x;,void func(Two,;,/不完全类申明(Two),以便在类One中引用Two,直接使用类Two私有组员,class Two,int y;,public:,Two(int b):y(b),int Gety()return y;,friend,void One:func(Two,;,void One:func(Two&r),r.,y,=x;,错误:不完全申明类不能实例化。,不能存取没有完全申明类组员。,41,第41页,第41页,#include,using namespace std;,class Two;,class One,int x;,public:,One(int a):x(a);,int Getx()return x;,void func(Two,;,class Two,int y;,public:,Two(int b):y(b),int Gety()return y;,friend void One:func(Two,;,void One:func(Two&r),r.y=x;,void main(),One obj1(5);,Two obj2(8);,coutobj1.Getx(),obj2.Gety()endl;,obj1.func(obj2);,cout,调用友元组员函数后,:,endl;,coutobj1.Getx(),obj2.Gety()endl;,5,8,调用友元组员函数后:,5,5,42,第42页,第42页,在类B中申明类A为B友元格式:,class B,friend class A,二、将一个类A阐明为另一类B友元,注:假如类A为类B友元,则类A中,所有组员函数均居于友元函数功效,。,43,第43页,第43页,class Two;,class One,int x;,public:,One(int a):x(a);,int Getx()return x;,void func(Two,;,class Two,int y;,public:,Two(int b):y(b),int Gety()return y;,;,void One:func(Two&r),r.y=x;,friend void One:func(Two,friend class One;,思考:,此申明能不能省略?,思考:,func函数定义可否放在类Two定义前?,不能,不能,void main(),One obj1(5);,Two obj2(8);,coutobj1.Getx(),obj2.Gety()endl;,obj1.func(obj2);,cout,调用友元组员函数后,:,endl;,coutobj1.Getx(),obj2.Gety()endl;,44,第44页,第44页,总结:,1、友元,申明与访问控制无关,。,在private和public后申明效果相同。,2、友元关系是,不能传递,。,若A是B友元,B是C友元,A不能自动称为C友元。,注意:此时哪个类能访问哪个类组员?,3、友元关系是,单向,。,若A是B友元,B不一定是A友元。,45,第45页,第45页,友元三种形式:,1,普通函数作一个类友元,2,a类组员函数作b类友元,3,a类作为b类友元,课程回顾,46,第46页,第46页,1.下列关于友元描述错误是(),A.组员函数不可作友元B.类能够作友元,C.普通函数能够作友元D.静态函数能够作友元,2.友元函数能够存取类_、公有组员和保护组员。,3.在C+中,即使友元提供了类之间数据进行访问一个方式,但它破坏了面向对象程序设计_特性。,4.假如类A被申明成类B友元,则(),A.类A组员即类B组员,B.类B组员即类A组员,C.类A组员函数不得访问类B组员,D.类B不一定是类A友元,A,私有组员,封装,D,47,第47页,第47页,5.对于友元描述正确是(),A友元是本类组员函数,B友元不是本类组员函数,C友元不是函数,D友元不能访问本类私有组员,B,48,第48页,第48页,6、给岀下列程序执行结果。,#include,class sample,int n;,public:,sample(int i)n=i;,friend int add(sample,;,int add(sample&s1,sample&s2),return s1.n+s2.n;,void main(),sample s1(10),s2(20);,coutadd(s1,s2)endl;,49,第49页,第49页,7、先找出程序中错误,更正后分析程序执行结果:,#include,class B;,class A,int i;,friend B;,void disp()coutiendl;,;,class B,public:,void set(int n),A a;a.i=n;,a.disp();,;,void main(),B b;,b.set(2);,50,第50页,第50页,作业,书本126页,编程题第1题,51,第51页,第51页,const变量定义时需要初始化,。,const int x=0;,const int*p=,int*const p=,const int*const p=,5.4const对象,const可限定变量、指针、对象、函数、函数参数、数据组员、组员函数。表示不可改变。,52,第52页,第52页,常量组员(const组员)包括:,常量数据组员(const数据组员),常引用(const限定引用),静态常数据组员(static const 数据组员),一、常量组员,尤其注意:,1)静态常数据组员仍保留静态组员特性,需要在,类外初始化,。,2)常量数据组员和常引用组员必须在,结构函数初始化列表中进行初始化,。,53,第53页,第53页,#include(lt5_7.cpp),using namespace std;,class Base,int x;,const int a;,/常数据组员,static const int b;,/静态常数据组员,const int&r;,/常引用,public:,Base(int,int);,void show()coutx,a,b endl;,void display(,const double&r,)coutrendl;,;,const int Base:b=125;,Base:Base(int i,int j):x(i),a(j),void main(),Base a1(104,118),a2(119,140);,a1.show();,a2.show();,a1.display(3.14159);,先找出程序中错误并更正,然后分析程序结果。,常数据组员必须通过初始化列表来取得初值,r(x),常数据组员和常引用都必须通过初始化列表来取得初值,r endl;,54,第54页,第54页,#include,using namespace std;,class Base,int x;,const int a;,static const int b;,const int&r;,public:,Base(int,int);,void show()coutx,a,b,r endl;,void display(,const double&ref,)coutrefendl;,;,const int Base:b=125;,Base:Base(int i,int j):x(i),a(j),r(x),void main(),Base a1(104,118),a2(119,140);double x=3.14159;,a1.show();,a2.show();,a1.display(x);,常引用做函数参数,只是把实参值提供应函数使用,不允许函数改变对象值。,55,第55页,第55页,引用作形参特点:,形参改变会使得实参改变,,引用作形参,形参不分派内存,有时需要使用引用作形参但要求形参不能改变,此时可使用const限定,二、const引用作参数,56,第56页,第56页,对象申明前加上,const,限定,普通定义格式为:,类名 const 对象名;,或者,const 类型 对象名,三、,常对象(const对象),比如:,base const a(25,68);,const base b(21,32);,注意:,1)在定义常对象时,必须进行初始化,。,2)常对象,数据组员不能被更新,。,57,第57页,第57页,分析下列程序结果,(lt5_7a.cpp),#include,using namespace std;,class base,int x,y;,public:,base():x(0),y(0),base(int a,int b):x(a),y(b),void show(),coutx,yendl;,cout+x,+yendl;,;,void main(),base a;,a.show();,base b(10,20);b.show();,58,第58页,第58页,#include,using namespace std;,class base,int x,y;,public:,base(),:x(0),y(0),base(int a,int b):x(a),y(b),void set(int a,int b)x=a;y=b;,void show(),coutx,yendl;,;,void main(),base a;,a.show();,const,base b(10,20);,编译错误:,不能改变常对象数据组员值,找出程序中错误,并阐明原因,a.set(1,2);,b.set(1,2);,b.show();,思考:如何显示b数据组员?,编译错误:常对象只能调用,常组员函数,。,59,第59页,第59页,四、常组员函数,使用const关键词申明函数为常组员函数,申明格式下列:,类型 函数名(参数表),const,;,注:,1)const是函数阐明一个构成部分,因此在,定义部分,也要带const关键词。,2)常组员函数不能更新对象数据组员,也不能调用该类中没有用const修饰组员函数。,3)一个const对象能够调用const函数,但不能调用非const组员函数。,4)const限定函数与未加const限定同名函数可重载。,5)const不可限定析构函数和结构函数。,60,第60页,第60页,#include,/lt5_7c.cpp,using namespace std;,class base,int x,y;,public:,base():x(0),y(0),base(int a,int b):x(a),y(b),void set(int a,int b)x=a;y=b;,void show(),coutx,yendl;,cout+x,+yendl;,;,void main(),base a;,a.show();,const base b(10,20);,/常对象,b.show();,const,常组员函数,编译错误:常对象只能调用,常组员函数,!,错误:在常组员函数中,不能更新对象数据组员,61,第61页,第61页,#include (lt5_7d.cpp),using namespace std;,class base,int x,y;,public:,base():x(0),y(0),base(int a,int b):x(a),y(b),void set(int a,int b)x=a;y=b;,void,show(),const,/const组员函数,coutx,yendl;,void,show(),/非const组员函数,coutx,yendl;,cout+x,+yendl;,;,void main(),base a;,a.show();,const base b(10,20);,b.show();,const限定函数与未加const限定同名函数可重载。,const组员函数与同名非const组员函数可重载。,62,第62页,第62页,练习:找出程序中错误并更正,然后分析程序结果(lt5_8.cpp),#include,using namespace std;,class base,double x,y;,const double p;,public:,base(double m,double n,double d):p(d),x=m;y=n;,void show();,void show()const;,;,void base:show(),coutx,y,p=pendl;,void base:show(),const,coutx,y,const p=pendl;,void main(),base a(8.9,2.5,3.1416);const base b(2.5,8.9,3.14);,a.show();b.show();,63,第63页,第63页,总结:,1,const数据组员必须在结构函数初始化列表中进行初始化。,2,const组员函数内不可出现任何改变变量值语句。,3,const对象只能使用const组员函数,不同对象能够使用全部组员函数。,4,const引用做参数时,函数体内不可出现改变参数值语句。,64,第64页,第64页,比如:假设已定义point类。,则point p3;,表示申明了一个含有3个元素数组p,其中每一个元素都是point类一个对象。,5.5 数组和类,类可定义对象数组和对象指针数组。,一、对象数组,对象数组是指元素都是对象数组。也就是说,假如某一个类有若干个对象,则能够把这一系列被创建对象用一个数组来存储。,申明格式:,类名 数组名对象个数,65,第65页,第65页,分析下列程序结果(lt5_10.cpp),class point,int x,y;,public:,point():,x(0),y(0),point(int a):,x(a)y=0;,point(int a,int b):,x(a),y(b);,int getx()return x;,int gety()return y;,;,void main(),point a3;,for(int i=0;i3;i+),coutai:ai.getx(),ai.gety()endl;,point b3=1,2,3;,for(i=0;i3;i+),coutbi:bi.getx(),bi.gety()endl;,point c3=point(1,2),point(3,4),point(5,6);,for(i=0;i3;i+),coutci:ci.getx(),ci.gety()endl;,/每个元素调用无参结构函数,/每个元素调用1个参数结构函数,/每个元素调用2个参数结构函数,编译器会调用适当结构函数来建立数组每一个分量,66,第66页,第66页,分析下列程序结果(lt5_10a.cpp),class point,int x,y;,public:,point(int a,int b):x(a),y(b);,int getx()return x;,int gety()return y;,void main(),point a3=point(1,2),point(3,4),point(5,6);,point*p=a;,/用指针指向数组元素,for(int i=0;i3;i+),coutai:,ai.,getx(),ai.,gety()getx(),(p+i)-gety(),67,第67页,第67页,二、类对象指针数组,int*p;表示定义一个指针变量,int p5;表示定义一个数组。,int*p5 表示定义一个有5个元素数组,其中每个元素都,是一个指针。这类数组称为,指针数组,。,若类point已经正拟定义下列:,class point,int x,y;,public:,point():x(0),y(0),point(int a):x(a)y=0;,point(int a,int b):x(a),y(b);,int getx()return x;,int g
展开阅读全文