程序是这样的:
//point.h
#include <iostream>
using namespace std;
class point
{
public:
point(int xx,int yy);
point(point &p1);
int getx();
int gety();
static int getc();
virtual ~point();
private:
int x;
int y;
static int countp;
};
//point.cpp
#include "point.h"
point::point(int xx,int yy)
{cout<<"构造函数被调用!"<<endl;
x=xx;
y=yy;
countp++;
}
point::~point()
{ cout<<"析构函数被调用!"<<endl;
countp--;
}
int point::getc()
{return countp;}
int point::getx()
{return x;}
int point::gety()
{return y;}
point::point(point &p1)
{x=p1.x;
y=p1.y;
countp++;
}
int point::countp=0;
//main.cpp
#include "point.h"
int main()
{
point p1(1,5);
point p2(2,5);
cout<<"p1点的x坐标是:"<<endl;
cout<<p1.getx()<<endl;
cout<<"p1点的y坐标是:"<<endl;
cout<<p1.gety()<<endl;
cout<<"p2点的x坐标是:"<<endl;
cout<<p2.getx()<<endl;
cout<<"p2点的y坐标是:"<<endl;
cout<<p2.gety()<<endl;
cout<<"此时共有的个数是:"<<endl;
cout<<p1.getc()<<endl;
return 0;
}
编译结果:
warning C4003: not enough actual parameters for macro 'getc'
h:\c++学习\随便练习\静态数据成员\point.h(20) : error C2059: syntax error : '--'
h:\c++学习\随便练习\静态数据成员\point.h(20) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
h:\c++学习\随便练习\静态数据成员\main.cpp(16) : warning C4003: not enough actual parameters for macro 'getc'
h:\c++学习\随便练习\静态数据成员\main.cpp(23) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
main.obj - 3 error(s), 2 warning(s)
程序是这样的,可编译时出现问题,我怎么也看不出是哪里有问题,清高手指点!!!谢谢!!