.h文件
#ifndef MYPOINT_H
#define MYPOINT_H
class Mypoint
{
public:
Mypoint();
Mypoint(double newX, double newY);
double x;
double y;
double getX();
double getY();
double distance(Mypoint point1, Mypoint point2);
};
#endif
.cpp文件
#include <cmath>
#include "Mypoint.h"
Mypoint::Mypoint()
{
x = 0;
y = 0;
}
Mypoint::Mypoint(double newX, double newY)
{
x = newX;
y = newY;
}
double Mypoint::getX()
{
return x;
}
double Mypoint::getY()
{
return y;
}
double Mypoint::distance(Mypoint point1, Mypoint point2)
{
return pow((point1.getX() - point2.getX()) * (point1.getX() - point2.getX()) + (point1.getY() - point2.getY()) * (point1.getY() - point2.getY()), 0.5);
}
测试文件
#include <iostream>
#include "Mypoint.h"
using namespace std;
;;
int main()
{
Mypoint point1;
Mypoint point2;
point1.Mypoint(0, 0);
point2.Mypoint(10, 30.5);
point1.distance(Mypoint point1, Mypoint point2);
return 0;
}
最后报错了