如果有人願意幫忙,我可以使用一些專業知識來調試我的代碼。我試圖從一個類文件調用一個函數,我遇到了一些錯誤。我正在學習C++。我的錯誤是如下:調試類函數實現C++
In function 'int main()':
error: no matching function for call to 'MyPoint::distance(MyPoint&)'
note: candidate is:
note: double MyPoint::distance(double)
Main.cpp的
#include <iostream>
#include <cmath>
#include "MyPoint.h"
using namespace std;
int main()
{
MyPoint point1;
MyPoint point2(10.2, 34.8);
cout << point1.distance(point2);
return 0;
}
MyPoint.h
#ifndef MYPOINT_H
#define MYPOINT_H
using namespace std;
class MyPoint
{
public:
MyPoint();
MyPoint(double, double);
double getX();
double getY();
double distance(double);
private:
double x, y;
};
#endif // MYPOINT_H
MyPoint.cpp
#include <iostream>
#include <cmath>
#include "MyPoint.h"
using namespace std;
MyPoint::MyPoint()
{
x = 0.0;
y = 0.0;
}
MyPoint::MyPoint(double x1, double y1)
{
x = x1;
y = y1;
}
double MyPoint::getX()
{
return x;
}
double MyPoint::getY()
{
return y;
}
double MyPoint::distance(double p2)
{
return sqrt((x - p2.x) * (x - p2.x) + (y - p2.y) * (y - p2.y));
}
謝謝...