
急求啊,c++程序问题,求解释。、、、
#include<iostream>usingnamespacestd;classPoint{public:Point(intxx=0,intyy=0){这里的xx,yy...
#include <iostream>
using namespace std;
class Point{
public:
Point(int xx=0,int yy=0){
这里的xx,yy是什么意思?
x=xx;
y=yy;
}
Point(Point&p);
这一步不懂。重点解释下&p
int getX(){
get代表什么?
return x;
也不懂
}
int getY(){
return y;
}
private:
int x,y;
};
Point::Point(Point&p){
x=p.x;
p.x什么意思?
y=p.y;
cout<<"Calling the copy constructor"<<endl;
}
void fun1(Point p){
fun1是什么?
cout<<p.getX()<<endl;
}
Point fun2()
这里的()为什么里面不用写东西,上面怎么要写fun1(Point p)??
{
Point a(1,2);
return a;
}
int main (){
主函数都看不懂,求解释啊。。
Point a(4,5);
Point b=a;
cout<<b.getX()<<endl;
fun1(b);
fun2();
cout<<b.getX()<<endl;
return 0;
} 展开
using namespace std;
class Point{
public:
Point(int xx=0,int yy=0){
这里的xx,yy是什么意思?
x=xx;
y=yy;
}
Point(Point&p);
这一步不懂。重点解释下&p
int getX(){
get代表什么?
return x;
也不懂
}
int getY(){
return y;
}
private:
int x,y;
};
Point::Point(Point&p){
x=p.x;
p.x什么意思?
y=p.y;
cout<<"Calling the copy constructor"<<endl;
}
void fun1(Point p){
fun1是什么?
cout<<p.getX()<<endl;
}
Point fun2()
这里的()为什么里面不用写东西,上面怎么要写fun1(Point p)??
{
Point a(1,2);
return a;
}
int main (){
主函数都看不懂,求解释啊。。
Point a(4,5);
Point b=a;
cout<<b.getX()<<endl;
fun1(b);
fun2();
cout<<b.getX()<<endl;
return 0;
} 展开
展开全部
1 #include <iostream>
2 using namespace std;
3 class Point{
4 public:
5 Point(int xx=0,int yy=0){
这里的xx,yy是什么意思?//xx yy是整型参数,x y是私有成员变量
6 x=xx;
7 y=yy;
}
8 Point(Point&p);
这一步不懂。重点解释下&p //p是Point对象参数,&表示引用
9 int getX(){
get代表什么?//get只不过是个函数名称,没什么特殊(Java中有特殊意义),可以改成a()或b()等等都行
10 return x;
也不懂//返回整型值x
11 }
12 int getY(){
13 return y;
14 }
15 private:
16 int x,y;
17};
18Point::Point(Point&p){ //自定义拷贝函数
19 x=p.x;
p.x什么意思?//p是个Poin对象,对象中有x y,见15,16行
20 y=p.y;
21 cout<<"Calling the copy constructor"<<endl;
22}
23void fun1(Point p){
24fun1是什么?//一个普通函数名,可以自定义的
25 cout<<p.getX()<<endl;
26}
27Point fun2()
这里的()为什么里面不用写东西,上面怎么要写fun1(Point p)??//这是无参数型,()中没东西说明没值传入
28{
29Point a(1,2);
30return a;
31}
32int main (){
主函数都看不懂,求解释啊。。//int 表示有返回值,一般与return 0配合用
33 Point a(4,5);//建立对象a,并初始化对象
34 Point b=a;//拷贝对象a
35 cout<<b.getX()<<endl;//输出对象中的x变量
36 fun1(b);//跟上句输出效果相同效果
37 fun2();//看函数体,返回一个a对象
38 cout<<b.getX()<<endl;//同35
39 return 0;//int main ()必须的,如果是void main()该句可以没有
}
ps:建议先看些基础知识,比如变量、参数、函数、类等等
2 using namespace std;
3 class Point{
4 public:
5 Point(int xx=0,int yy=0){
这里的xx,yy是什么意思?//xx yy是整型参数,x y是私有成员变量
6 x=xx;
7 y=yy;
}
8 Point(Point&p);
这一步不懂。重点解释下&p //p是Point对象参数,&表示引用
9 int getX(){
get代表什么?//get只不过是个函数名称,没什么特殊(Java中有特殊意义),可以改成a()或b()等等都行
10 return x;
也不懂//返回整型值x
11 }
12 int getY(){
13 return y;
14 }
15 private:
16 int x,y;
17};
18Point::Point(Point&p){ //自定义拷贝函数
19 x=p.x;
p.x什么意思?//p是个Poin对象,对象中有x y,见15,16行
20 y=p.y;
21 cout<<"Calling the copy constructor"<<endl;
22}
23void fun1(Point p){
24fun1是什么?//一个普通函数名,可以自定义的
25 cout<<p.getX()<<endl;
26}
27Point fun2()
这里的()为什么里面不用写东西,上面怎么要写fun1(Point p)??//这是无参数型,()中没东西说明没值传入
28{
29Point a(1,2);
30return a;
31}
32int main (){
主函数都看不懂,求解释啊。。//int 表示有返回值,一般与return 0配合用
33 Point a(4,5);//建立对象a,并初始化对象
34 Point b=a;//拷贝对象a
35 cout<<b.getX()<<endl;//输出对象中的x变量
36 fun1(b);//跟上句输出效果相同效果
37 fun2();//看函数体,返回一个a对象
38 cout<<b.getX()<<endl;//同35
39 return 0;//int main ()必须的,如果是void main()该句可以没有
}
ps:建议先看些基础知识,比如变量、参数、函数、类等等
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询