Hi, I'm a first year c++ programmer and am having trouble with this code.
The errors are...
error C2059: syntax error : ']'
for this line
drawPolyLine(x,y,no_points,objects[MAX_POINTS]);
saying objects is not compatible as int to int*(you'll notice I do not have it as a pointer anywhere)
Here is the code..
#include <iostream>
#include "graph1.h"
using namespace std;
//Function Prototypes Follow
void getNoPoints(int* no_points);
void getPoints(int* x, int* y,int no_points);
void drawPolyLine(int* x, int* y, int no_points,int objects[]);
int main()
{
//Variable Declaration/Initialization
int no_points = 0;
const int MAX_POINTS = 10;
int x[MAX_POINTS];
int y[MAX_POINTS];
int no_circles = 0;
int objects[MAX_POINTS];
//Display Graphics Window
displayGraphics();
//Get the number of points (pass the address of no_points )
getNoPoints(&no_points);
//Get the data for the points
getPoints(x,y,no_points);
//Draw the polyline
drawPolyLine(x,y,no_points,objects[MAX_POINTS]);
my professor spent all of 2 minutes telling us about pointers, I'm incredibly confused about what I'm doing for this code and am at the point where I'm just trying to appease the compiler and the way I have it now comes up with the least(and least confusing)errors.If i take away the asterisk it says subscript requires array or pointer type at lines 66,67,and line 74.
Yes, because your code requires you to provide an array, or pointer. So you need to provide an array to it. You did managed to do this for x and y. I do not see why it is a problem now.
I understand that, however my professor expressed to us that each variable should be executed as a pointer. I figure I'll have to just make an array for it and take whatever deductions he sets because I'm at a loss. Thank you so much for replying.
1) as editing a post will not notify anyone it is better to leave message in thread instead.
2) Do the same as you did for x and y. Exactly same thing.
1 2 3 4 5 6 7 8
int x[MAX_POINTS];
int objects[MAX_POINTS];
//↓ Why the difference? ↓
drawPolyLine(x,y,no_points,objects[MAX_POINTS]);
// int objects is equivalent to int* objects ↓
void drawPolyLine(int* x, int* y, int no_points,int objects[])
OOOOHHHHHHHH!!!!!!! It all makes sense now! That made it run, now I just have to figure out why my graphics aren't what they're supposed to be, thanks so much!
drawPolyLine(x,y,no_points,objects); //objects[MAX_POINTS] will pass single (and invalid btw) element
void drawPolyLine(int* x, int* y, int no_points,int* objects) //No difference with current way, but is more consistent with other paramerters