//頭檔案
#pragma once
#include <iostream>
class SD_Point
{
float x, y;
public:
void Set_Point(float, float);
float Get_X();
float Get_Y();
void Get_Point();
SD_Point();
SD_Point(float, float);
float operator*(SD_Point);
friend ostream& operator<< (ostream&, SD_Point&);
};
//實作檔案
#include "SD_Point.h"
#include <iostream>
#include <math.h>
using namespace std;
SD_Point::SD_Point()
{
x = y = 0;
}
SD_Point::SD_Point(float x, float y)
{
this->x = x;
this->y = y;
}
void SD_Point::Set_Point(float x, float y)
{
this->x = x;
this->y = y;
}
float SD_Point::Get_X()
{
return x;
}
float SD_Point::Get_Y()
{
return y;
}
void SD_Point::Get_Point()
{
cout << "(" << x << "," << y << ")" << endl;
}
float SD_Point::operator*(SD_Point point)
{
float d;
d = (float)sqrt(pow(this->x - point.x, 2) + pow(this->y - point.y, 2));
return d;
}
ostream & operator <<(ostream& out, SD_Point& point)
{
out << "(" << point.Get_X() << "," << point.Get_Y() << ")" << endl;
return out;
}
//包含主函式的檔案
#include "SD_Point.h"
#include <iostream>
using namespace std;
int main()
{
SD_Point point(1, 3);
cout << point << endl;
}
uj5u.com熱心網友回復:

這是報錯的資訊。
uj5u.com熱心網友回復:
樓主這些都是語法錯誤,試了下上面的代碼,編譯運行沒發現問題。建議放在一個檔案除錯修改,成功了再分檔案。(1,3)
請按任意鍵繼續. . .
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/278194.html
標籤:C++ 語言
上一篇:怎么用vscode讀寫文本檔案
下一篇:冒泡排序
