我一直遇到一个错误,我不知道该怎么解决
I keep getting an error that i cannot figure out how to fix
这是我的一个类中的编程赋值。我应该取一个点的列表,并根据与参考点的距离对它们进行排序。提示说使用一个结构来存储每个点的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;
};
否则,pointsarray
是Points*
的阵列,而不是Point*
的阵列。这就是编译器不喜欢以下语句的原因:
points->pointsarray[i] = point;
该线的RHS侧是Point*
,而不是Points*
。
相关文章:
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 我正在尝试使用 c++ 创建一个货币转换程序,我不知道如何继续
- 我不知道这条线是做什么的
- 如果我不知道每个列表中有多少个数字,我如何将给定数量的数字列表作为输入?
- 我不知道导致错误的原因 (C3074)
- 我不知道为什么这段代码会让核心被转储?
- 我正在尝试制作一个自平衡机器人,但编译时存在错误。我不知道如何解决它
- 我不知道如何使用代码块win32 gui
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- if-else 语句仅按特定顺序工作,我不知道为什么
- DirectX 11 引擎在第三次代码改进后没有突然运行,我不知道为什么
- 程序输入名称和高度并显示它。我不知道如何显示列表中最高人的姓名和身高
- 函数抛出seg错误,我不知道为什么
- 我不知道为什么复制构造函数的调用在 c++ 中不稳定
- 我自己解决的。指针,但我不知道为什么
- 双乘法四舍五入,我不知道如何解决
- LNK2005,我不知道我能做些什么来解决这个问题
- 创建一个有三种方法可供选择的加密程序!它有问题,我不知道如何解决
- 我一直遇到一个错误,我不知道该怎么解决