首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

帮小弟我看下这段程序

2012-03-09 
帮我看下这段程序#includeiostream.hclassPoint{public:Point(intxx0,intyy0){XxxYyycountP++}Po

帮我看下这段程序
#include   <iostream.h>
class   Point
{
public:
Point(int   xx=0,int   yy=0)
{
X=xx;
Y=yy;
countP++;
}
Point(Point   &p);
int   GetX()
{
return   X;
}
int   GetY()
{
return   Y;
}
void   Get()
{cout < < "object   id= " < <countP < <endl;
}
private:
int   X,Y;
static   int   countP;
}
Point::Point(Point   &p)
{
X=p.X;
Y=p.Y;
countP++;
}
int   Point::countP=0;
void   main()
{
Point   A(4,5);
cout < < "Point   A( " < <A.GetX() < < ", " < <A.GetY() < < ") ";
A.Get();
Point   B=A;
cout < < "Point   B( " < <B.GetX() < < ", " < <A.GetY() < < ") ";
B.Get();
}
在VC6.0环境下调试,出现问题:
一、error   C2533:   'Point::Point '   :   constructors   not   allowed   a   return   type
二、error   C2264:   'Point::Point '   :   error   in   function   definition   or   declaration;   function   not   called
执行   cl.exe   时出错.
请问怎么修改啊?

[解决办法]
// ...
int X,Y;
static int countP;
}; // 这里少了一个分号
[解决办法]
.........
private:
int X,Y;
static int countP;
}

-------------------------------
你定义类时,漏写了分号啊!!

即是
......................
private:
int X,Y;
static int countP;
}; -> 此处加上分号啊!!

[解决办法]
#include <iostream.h>

class Point
{
public:
Point(int xx=0,int yy=0)
{
X=xx;
Y=yy;
countP++;
}
Point(Point &p);
int GetX()
{
return X;
}
int GetY()
{
return Y;
}
void Get()
{cout < < "object id= " < <countP < <endl;
}
private:
int X,Y;
static int countP;
};
Point::Point(Point &p)
{
X=p.X;
Y=p.Y;
countP++;
}
int Point::countP=0;

void main()
{
Point A(4,5);
cout < < "Point A( " < <A.GetX() < < ", " < <A.GetY() < < ") ";
A.Get();
Point B=A;
cout < < "Point B( " < <B.GetX() < < ", " < <A.GetY() < < ") ";
B.Get();
}
[解决办法]
private:
int X,Y;
static int countP;
};
是呀!这个}后应该加上一个分号,加上后就正确了!
[解决办法]
类声明后面忘记分号了

热点排行