C++编程程序出错

来源:百度知道 编辑:UC知道 时间:2024/09/21 15:29:22
我写了一个工作空间
point.h文件这样写
class point
{
int x,y;
public:
int getx();
int gety();
point(int x=0,int y=0);
};
类的实现这样写
#include<iostream>
using namespace std;
#include"point.h"
point::point(int xx=0,int yy=0)
{x=xx;y=yy;}
int point::getx()
{return(x);}
int point::gety()
{return(y);}
主调用函数这样写
#include"point.h"
main()
{
point A(3,4);
A.gety();
}
出错了,请问怎么改???
出错在哪了?

point.h文件这样写
class point
{
int x,y;
public:
int getx();
int gety();
point(int x=0,int y=0);
};
这里是类定义存储在point.h文件

类的实现这样写并存储point.cpp文件

#include<iostream>
using namespace std;
#include"point.h"
point::point(int xx=0,int yy=0)
{x=xx;y=yy;}
int point::getx()
{return(x);}
int point::gety()
{return(y);}

主调用函数这样写
#include<iostream>
#include"point.cpp" //在这里使用"point.cpp"而不是point.h
int main()
{
point A(3,4);
A.gety();
}

还有一种方法较预处理器封套
point.h文件这样写
#ifndef POINT_H
#define POINT_H
class point
{
int x,y;
public:
int getx();
int gety();
point(int x=0,int y=0);
};
#endif
类的实现这样写并存储point.cpp文件

#include<iostream>
using namespace std;
#include"point.h"
point::point(int xx=0,int yy=0)