Unknown solution to error
Apr 15, 2014 at 1:35am UTC
I am getting two compiler errors in which it states that point and points was not declared in this scope and they both occur in RenderOrder.cpp. Since both structs are declared in my header files, would they not work since I #include both header files?
RENDERORDER
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include "Point.h"
#include "Points.h"
#include <iostream>
#include "TextConversion.h"
using namespace std;
//void sortPointsByDistanceFromRefPoint(Points* points, Point* ref_point);
int main(int argc, char ** argv)
{
if (argc != 5)
{
cout << "Incorrect number of parameters." << endl;
}
char * file_name = argv[1];
string x_text = argv[3];
string y_text = argv[4];
string z_text = argv[5];
double x = a_to_d(x_text);
double y = a_to_d(y_text);
double z = a_to_d(z_text);
createPoint(x, y, z);
readPoints(file_name);
displayPoints(points);////////////
//sortPointsByDistanceFromRefPoint(points, ref_point);
displayPoints(points);
destroyPoint(point); ////////
destroyPoints(points);
return 0;
}
//void sortPointsByDistanceFromRefPoint(Points* points, Point* ref_point)
POINT.CPP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <iostream>
#include "Point.h"
#include "Points.h"
using namespace std;
Point* createPoint(double x, double y, double z)
{
Point* point = new Point;
point->x = x;
point->y = y;
point->z = z;
return point;
}
void destroyPoint(Point* point)
{
delete point;
}
void displayPoint(const Point* const point)
{
cout <<"Reference points" << point->x << " " << point->y << " " << point->z << endl;
}
POINTS.CPP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include <fstream>
#include "Point.h"
#include "Points.h"
Points* readPoints(const char * file_name)
{
ifstream input_file;
input_file.open(file_name);
Points* points = new Points;
input_file >> points->num_points;
int num_points = points->num_points;
points->points = new Point*[num_points];
for (int i = num_points; i >= 0; i--)
{
points->points[i] = new Point;
Point* point = points->points[i];
input_file >> points->num_points;
input_file >> point->x;
input_file >> point->y;
input_file >> point->z;
}
input_file.close();
return points;
}
void destroyPoints(const Points* points)
{
int num_points = points->num_points;
for (int i = num_points; i <= 0; i--)
{
delete points->points[i];
}
delete [] points->points;
points = NULL;
}
void displayPoints(const Points* points)
{
int num_points = points->num_points;
for (int i = num_points; i >= 0; i--)
{
Point* point = points->points[i];
}
}
Apr 15, 2014 at 1:43am UTC
What do Point.h and Points.h contain? Could you paste the errors you're getting (you don't need to post full paths if you're getting them)
Last edited on Apr 15, 2014 at 1:44am UTC
Apr 15, 2014 at 1:47am UTC
POINT.H
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#if !defined POINT
#define POINT
using namespace std;
struct Point
{
double x;
double y;
double z;
};
Point* createPoint(double x, double y, double z);
void destroyPoint(const Point* point);
void displayPoint(const Point* const point);
#endif
POINTS.H
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#if !defined POINTS
#define POINTS
#include "Point.h"
struct Points
{
Point** points;
int num_points;
};
Points* readPoints(const char * file_name);
void destroyPoints(const Points* points);
void displayPoints(const Points* points);
#endif
RenderOrder.cpp: In function 'int main(int, char**)':
RenderOrder.cpp:31:15: error: 'points' was not declared in this scope
RenderOrder.cpp:35:14: error: 'point' was not declared in this scope
Apr 15, 2014 at 3:38am UTC
1 2 3 4 5
//in line 28
Point * point = createPoint(x, y, z);
Points* points = readPoints(file_name);
displayPoints(points);///////////
Topic archived. No new replies allowed.