View Single Post
  #2   Spotlight this post!  
Unread 01-05-2013, 21:20
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: [Q] I need help with passing an array of pointers to an object

First of all, you can make
Code:
for (int x = 0; x < 10; x++) {
		buttons[x] = false;
	}
into this:

Code:
buttons = {0}; //This fills the array with 0's, which is equivalent to false.
Secondly, I am partial against using the "<=" operator in a for loop; I suggest just sticking with "<".

*victor points to the pointer to a pointer to an array of pointers to Victor objects. Now, what many C/C++ novices overlook is the fact that the array and pointer notations are interchangeable. So, let's see this example:

Code:
int foo[10] = {0};
for(int i = 0; i < 10; i++)
  foo[i] = i;
//Is the same as this:
for(int i = 0; i < 10; i++)
  *(foo+i) = i;
So, that being said, look at how you declared your Victor array. I don't think you are doing what you are trying to do.

I would do:
Code:
Victor **victors;
//All the other stuff...

JoystickInput::JoystickInput(Joystick * joy, Victor **vicArray) {
	joystick = joy;
	buttons = {0};
	victors = vicArray;
	}

//Then when you declare that array that you pass in:

Victor *drivers = new Victor[8];

//Fill the array like drivers[0] = new Victor();
//Then pass it into the function.

JoystickInput(joy, &drivers);
Hopefully that helps. I might have made a simple mistake here or there, but keep in mind that I've been almost exclusively been programming in C this year.

Last edited by davidthefat : 01-05-2013 at 21:33.
Reply With Quote