Pointers in C++

Soldato
Joined
16 Jan 2003
Posts
4,948
Location
Kirkcaldy, Scotland
I'm currently programming a robot to navigate around a factory for uni using C++ but being an Engineer and not a programmer I dont really know much about C++. I've written a function called routefinder that is passed in the startx,startx,desiredx,desiredy cordinates. The program uses global variables which contain the location of objects around the factory. The function is to return the number of turning points and also output these turning points to a global array. How do I tell the function to output the points to a global array as it goes along?

Bellow is a little snippet of code, in bold are the two arrays I would like to be accessable outside the function.


int RouteFinder1(int Start_X,int Start_Y,int Desired_X,int Desired_Y)
{ //Subroutine Start

int Pillar1_X,Pillar1_Y,Pillar2_X,Pillar2_Y,Pillar3_X,Pillar3_Y,Pillar4_X,Pillar4_Y;
int flag = 0, NavPointCounter = 0,Current_X,Current_Y;

Current_X = Start_X;
Current_Y = Start_Y;
/* Up Then Right /*
/**************************************************************/

if (Desired_X > Start_X && Desired_Y > Start_Y)
{ //Open main loop 1

while (Current_Y < Desired_Y)
{ //Loop1
Current_Y ++;
flag == 0;
if (Current_Y == Desired_Y)
{
NavPointsX[NavPointCounter] = Current_X;
NavPointsY[NavPointCounter] = Current_Y;
NavPointCounter++;

}
 
instead of creating the arrays inside the function, create them in the constructor and declare tham as class variables the routefinder method can now use them easily. Alternativly you could create them in the main method and pass pointers too them around but tbh that just seems like a waste of time.

HT
 
happytechie said:
instead of creating the arrays inside the function, create them in the constructor and declare tham as class variables the routefinder method can now use them easily. Alternativly you could create them in the main method and pass pointers too them around but tbh that just seems like a waste of time.

HT

My programing knoledge is none existant, as far as I know a contstructor is a guy who makes things. How do I declare them as class variables as I'm not quite sure what you mean.

EDIT, never mind, I figured out what you meant, thanks :)
 
Last edited:
I have to say that if your programming knoledge is non existant you might be setting the target a bit high :eek: but good luck anyway ;)

have you got it all working or has C++ killed your brain?

HT
 
Back
Top Bottom