NEW QUESTION EDIT: cannot convert int to int*

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]);

return 0;
}

//Function Implementation Follows
void getNoPoints(int* no_points)
{
cout<<"Enter # of points: ";
cin>>*no_points;
}
void getPoints(int* x, int* y,int no_points)
{
//Variable Declaration/Initiliation
int i=0;

for(i=0;i<no_points;i++)
{
cout<<"Enter x/y coord for point #"<<(i+1)<<": ";
cin>>x[i]>>y[i];
}
}

void drawPolyLine(int* x, int* y, int no_points,int objects[])
{
int i=0;

for (i = 0; i < no_points;)
{
objects[i] = drawLine(x[i],y[i],x[++i],y[++i],1);
setColor(objects[i],255,255,0);
}

//Display each circle

for (i = 0; i < no_points; i++)
{
objects[i] = drawCircle(5,x[i],y[i]);
}
}
Last edited on
Lets play a game: spot the difference between declaration and definition.
1
2
void drawPolyLine(int* x, int* y, int no_points,int  objects);
void drawPolyLine(int* x, int* y, int no_points,int* objects)
When I fix the difference it comes up with this error
error C2664: 'drawPolyLine' : cannot convert parameter 4 from 'int' to 'int *'
That is because objects are not a pointer.
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!
Last edited on
1
2
3
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 
now I just have to figure out why my graphics aren't what they're supposed to be, thanks so much!
Topic archived. No new replies allowed.