把类中的成员函数作为另一个类的成员函数是出现的问题,求解。。。。。。。。。。

头文件point_dist.h

#include <iostream>
#include <math.h>
using namespace std;
class Point;

class Dist
{
/*   private:
	    Point point3(0,0),point4(0,0);    */

/*若加上此处,则会显示 IntelliSense: 应输入类型说明符,为什么?????????????????????????????
??????????????????????????????????*/

public:
	void cDist(Point &cPoint1,Point &cPoint2);	
};

class Point
{
private:
	int x,y;
public:
	Point(int CS_x=0,int CS_y=0)
	{
	    x=CS_x;
		y=CS_y;
	}
	Point(Point &p)
	{
	    x=p.x;
		y=p.y;
	}
	void setPoint(int getX,int getY)
	{
	    x=getX;
	    y=getY;
	}
	void showPoint()
	{
	    cout<<"横坐标:"<<x<<" 纵坐标:"<<y<<endl;
	}
	friend void Dist::cDist(Point &cPoint1,Point &cPoint2);
};

出现 IntelliSense: 应输入类型说明符

源文件mainFunction.cpp

#include "point_dist.h"
void Dist::cDist(Point &cPoint1,Point &cPoint2)
{
	double m=pow(double(cPoint1.x-cPoint2.x),2)+pow(double(cPoint1.y-cPoint2.y),2);
    cout<<"距离:"<<sqrt(m)<<endl;
}
int main()
{
   Point point1(15,45),point2(8,96);
   Dist dist;
   dist.cDist(point1,point2);
   system("pause");
   return 0;
}

2.若把Dist类与Point类定义倒过来也有错。。。。。。。。。。

头文件point_dist.h

#include <iostream>
#include <math.h>
using namespace std;
class Dist;
class Point     //先定义Point再定义Dist
{
private:
	int x,y;
public:
	Point(int CS_x=0,int CS_y=0)
	{
	    x=CS_x;
		y=CS_y;
	}
	Point(Point &p)
	{
	    x=p.x;
		y=p.y;
	}
	void setPoint(int getX,int getY)
	{
	    x=getX;
	    y=getY;
	}
	void showPoint()
	{
	    cout<<"横坐标:"<<x<<" 纵坐标:"<<y<<endl;
	}
	friend void Dist::cDist(Point &cPoint1,Point &cPoint2);
};
class Dist
{

public:
	void cDist(Point &cPoint1,Point &cPoint2);	
};

在这里插入图片描述
为什么呢????????????

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是一个求解Ax=b的C++函数代码,该函数是矩阵成员函数: ```c++ #include <iostream> #include <vector> using namespace std; class Matrix { private: int rows, cols; vector<vector<double>> data; public: Matrix(int r, int c) : rows(r), cols(c), data(vector<vector<double>>(r, vector<double>(c))) {} void set(int i, int j, double val) { data[i][j] = val; } void print() { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { cout << data[i][j] << " "; } cout << endl; } } vector<double> solve(vector<double>& b) { if (rows != cols || rows != b.size()) { throw "Invalid input!"; } vector<vector<double>> A(rows, vector<double>(cols + 1)); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { A[i][j] = data[i][j]; } A[i][cols] = b[i]; } for (int i = 0; i < rows; i++) { int pivot = i; for (int j = i + 1; j < rows; j++) { if (abs(A[j][i]) > abs(A[pivot][i])) { pivot = j; } } if (pivot != i) { swap(A[i], A[pivot]); } for (int j = i + 1; j <= cols; j++) { A[i][j] /= A[i][i]; } for (int j = i + 1; j < rows; j++) { for (int k = i + 1; k <= cols; k++) { A[j][k] -= A[j][i] * A[i][k]; } } } vector<double> x(cols); for (int i = cols - 1; i >= 0; i--) { x[i] = A[i][cols]; for (int j = i + 1; j < cols; j++) { x[i] -= A[i][j] * x[j]; } } return x; } }; int main() { Matrix A(3, 3); A.set(0, 0, 2); A.set(0, 1, -1); A.set(0, 2, 0); A.set(1, 0, -1); A.set(1, 1, 2); A.set(1, 2, -1); A.set(2, 0, 0); A.set(2, 1, -1); A.set(2, 2, 2); vector<double> b{1, 2, 3}; try { vector<double> x = A.solve(b); for (int i = 0; i < x.size(); i++) { cout << "x" << i + 1 << " = " << x[i] << endl; } } catch (const char* msg) { cerr << msg << endl; } return 0; } ``` 这个函数使用了高斯-约旦消元法来求解Ax=b,其A是一个矩阵,b是一个列向量,x是一个列向量,表示方程组Ax=b的解。在代码,我们首先将A和b组合成一个增广矩阵,然后使用高斯-约旦消元法将其化为行阶梯形式,最后通过回带法求解x。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦年华a

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值