我一直遇到一个错误,我不知道该怎么解决

I keep getting an error that i cannot figure out how to fix

本文关键字:我不知道 解决 错误 一个 遇到 一直      更新时间:2023-10-16

这是我的一个类中的编程赋值。我应该取一个点的列表,并根据与参考点的距离对它们进行排序。提示说使用一个结构来存储每个点的x、y、z值,并使用另一个结构存储点和点数。当我试图编译说时,我遇到了一个错误

Points.h:6:2: error: 'Point' does not name a type
Points.cpp: In function 'Points* readPoints(const char*)':
Points.cpp:25:11: error: 'struct Points' has no member named 'pointsarray'

是什么导致了这个错误,我该如何修复它?有四个文件与此有关,Points.h、Point.h、Points.cpp、Point.cpp.

这是Points.h的复制粘贴:'

#if !defined POINTS
#define POINTS
struct Points
{
    Point** pointsarray;
    int num_points;
};
Points* readPoints(const char file_name[]);
void destroyPoints(Points* pointsarray);
void DisplayPoints(Points* pointsarray);



#endif

这是Points.cpp的副本:

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#include "Points.h"
#include "Point.h"
Points* readPoints(const char file_name[])
{
    ifstream input_file;
    input_file.open(file_name);
    int ARRAY_SIZE = 0;
    input_file >> ARRAY_SIZE;
    int i = 0;
    double x = 0;
    double y = 0;
    double z = 0;
    Points* points;
    points->num_points = ARRAY_SIZE;
    for(i = 0; i < ARRAY_SIZE; i++){
        input_file >> x;
        input_file >> y;
        input_file >> z;
        Point* point = createPoint(x,y,z);
        points->pointsarray[i] = point;
    }
    return points;
}

这里是Point.cpp:

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
#include "Point.h"
#include "Points.h"
#if !defined NULL
#define NULL = 0
#endif

Point* createPoint(double x, double y, double z)
{
    Point* point;
    point.x = x;
    point.y = y;
    point.z = z;
    return point;
}
void destroyPoint(Point* point)
{
    delete point;
}
void displayPoint(Point* point)
{
    cout << setprecision(3) << fixed << "(" << point->x << ", " << point->y << ", " << point->z << ")" << endl;
}

这是要点。h

#if !defined POINT
#define POINT
struct Point
{
    double x;
    double y;
    double z;
};
Point* createPoint(double x, double y, double z);
void destroyPoint(Point* point);
void displayPoint(Point* point);
#endif

我非常感谢你能给我的任何解决方案,提前谢谢。

您有:

struct Points
{
    Points** pointsarray;
    int num_points;
};

也许你的意思是:

struct Points
{
    Point** pointsarray;
    int num_points;
};

否则,pointsarrayPoints*的阵列,而不是Point*的阵列。这就是编译器不喜欢以下语句的原因:

    points->pointsarray[i] = point;

该线的RHS侧是Point*,而不是Points*